Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
yatagan
Aug 31, 2009

by Ozma

mister_gosh posted:

Right but what would "18" be?


Have you tried googling "win32 error 18"?

ERROR_NO_MORE_FILES
18 (0x12)

or

ERROR_BAD_LENGTH
24 (0x18)

Adbot
ADBOT LOVES YOU

mister_gosh
May 24, 2002

Thank you!! I had tried googling but my search was too refined, I think.

Not sure what it means because the process finishes successfully but at least it's better than 18.

mister_gosh
May 24, 2002

It seems that 5.10 (was working fine in 5.8.3) introduced some extra tainting security on looking up environment variables. At least I think that is the problem but I'm not quite clear on how to fix it. Google only mentions the "PATH" variable and it appears they have some hard-coding in the solution, which isn't making sense to me.

This used to work:

my $myVar = $ENV{'MYVAR'}; # typically this would be "D:\mypath\myfile" but it could be anything

Now it is just a blank value.

Edit: its a USER variable, moved it to SYSTEM and it works fine. Not sure what is different now.

mister_gosh fucked around with this message at 21:42 on Jun 11, 2010

welcome to hell
Jun 9, 2006
Win32::FormatMessage will convert an error code taken from GetLastError to an error message.

You should test the return value of Win32::Process::Create to check if there was an error before using GetLastError.

Environment variables set for the user will not apply to a process running as a service or different user.

SynVisions
Jun 29, 2003

I'm trying to capture the results of a ALTER TABLE and it seems to not be working properly.

Code snippet:


code:
56    my $dbquery = "alter table tablename reorganize partition p0, p1 into (
57                     partition p1 values less than (1)";
58    my $sth = $dbh->prepare($dbquery) or die "Could not prepare statement: " . $dbh->errstr;
59    $sth->execute or die "Could not execute statement: " . $dbh->errstr;
60
61    # This doesn't work either
62    # my @res = $sth->fetchrow_array;
63
64    print $sth->dump_results;
on execution:

code:
0 rows (19: fetch() without execute())

DBD::mysql::st dump_results failed: fetch() without execute() at ./rotatePartitions.pl line 64.
Ignore the actual partition operation, I cut out the variables to make it more readable, the only thing that should be relevant there is that it successfully reorganizes the partitions.

I get the same error if I try any of the standard fetch functions.

I just want to capture the output in case something (anything) goes wrong but I'm struggling to find the proper way to validate the results of something that is actually altering the structure of the table because there could presumably be a lot more that could go wrong.

Anyway, if I could just get the return output without error, I could die if I see anything but the current "correct" output.

SynVisions fucked around with this message at 01:08 on Jun 26, 2010

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

SynVisions posted:

I'm trying to capture the results of a ALTER TABLE and it seems to not be working properly.
You want this: http://search.cpan.org/~timb/DBI-1.611/DBI.pm#do

Also, do yourself and everyone else you work with a favor and learn how to use the other shortcut methods of DBI. You really only need to prepare and execute and fetch very rarely.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
Alter does not return a result set*. If the execute doesn't die, it was successful. Capture in an eval block if you want error detection, as opposed to success detection.

* as far as I know on SQL Server. Typically only SELECT statements do, barring some weird DB implementations

SynVisions
Jun 29, 2003

Mithaldu posted:

You want this: http://search.cpan.org/~timb/DBI-1.611/DBI.pm#do

Also, do yourself and everyone else you work with a favor and learn how to use the other shortcut methods of DBI. You really only need to prepare and execute and fetch very rarely.

Good to know, thanks. A lot of this just comes from building on the code of others, I haven't read through the DBI documentation extensively -- but taking a glance around there I see the other shortcuts, so that should definitely help with the readability.

SynVisions fucked around with this message at 02:32 on Jun 26, 2010

TiMBuS
Sep 25, 2007

LOL WUT?

What do you guys think of the perl 6 logo?

She is called 'Camelia'.
the reasoning behind it is explained here: http://svn.pugscode.org/pugs/misc/camelia.txt

But there is a bit of arguing going on about it at the moment (spurred by the recent rakudo star announcement). 'Sri' made a few logo mockups for perl6 and now some people are trying to get it pushed as th new logo. Here is one of his designs:


The probplem is while some people (including some rakudo devs) like it, no single person is just going to up and say 'yep thats going to be the new one'. Ultimately it boils down to the community needing to decide on a logo, rather than a person at the top of the dev team (that would be you guys).
So.. Discuss! All your opinions will be fed back to perl6 developers. Thanks

Rohaq
Aug 11, 2006
The Camelia logo looks like it it's being aimed at children aged 0-3. I much prefer Sri's effort there; where do we go to voice our opinions?

TiMBuS
Sep 25, 2007

LOL WUT?

well you can hit up #perl6 on freenode, but they might not be in the mood for any more discussion about it at the moment. you can probably leave a message on the perl6 mailing list too.
i will also report any fruitful discussion had here itt

TiMBuS
Sep 25, 2007

LOL WUT?

Rohaq posted:

The Camelia logo looks like it it's being aimed at children aged 0-3. I much prefer Sri's effort there; where do we go to voice our opinions?

If you read larrys reasoning behind the logo it really justifies why he made camelia. Do you think sri's logo also meets the listed requirements? can you think of a way to improve either logo?

E: im not arguing for camelia because I prefer it (I don't tbh), I'm just prompting deeper discussion here.

Rohaq
Aug 11, 2006
They seem to be obsessing over making Perl 6 look 'fun', but have gone completely off the deep end by turning the logo into a character from a children's TV show. Perl is pretty alright to code in, some might even say 'fun', but it stands for 'Practical Extraction and Report Language': it's used to do some pretty drab and serious work-type things.

Also, it's difficult to see how the logo is even related to Perl: The logo suggests virtually nothing related to Perl on it's own, without telling somebody, and I can't see this logo appearing next to a 'Perl' header without looking mildly ridiculous - I didn't even spot the 'P6' in the wings until I had a really close look at it.

Sri's logo looks good next to the 'Perl' header, and it simple enough that it would stick in people's minds after seeing it, without any of the potential negative connotations of 'looking like a kid's MSpaint drawing'.

Rohaq
Aug 11, 2006

TiMBuS posted:

If you read larrys reasoning behind the logo it really justifies why he made camelia. Do you think sri's logo also meets the listed requirements? can you think of a way to improve either logo?
It seems to fill out most the requirements better than Camelia does, in my opinion. Going through the list:

Fun - Winner: Camelia
Cool - Winner: Sri
Cute - Tied
Named - Winner: Camelia, although we can think up a name for Sri's butterfly.
Lively - Tied
Punable - This is not a word.
Personal - Tied
Concrete - Winner: Sri
Symmetric ---- These two clash completely, but Tied.
Asymmetric -^
Attractive - Winner: Sri
Relational - Winner: Sri
Metamorphic - Tied
Decolorizable - Winnder: Sri - More basic colours put it on top here.
Shrinkable to textual icon - Winner: Sri
Shrinkable to graphical icon - Winner: Sri

So in my books, Camelia comes out on top for 2, they tie on many, but Sri's logo comes out on top for a whopping 7 of the requirements. Many of these are down to some pretty basic design errors in Camelia - It's too busy for a logo; logos should be relatively simple to allow for easy reproduction at various sizes, and for easy recognition by your target audience. Camelia just doesn't do that.

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

TiMBuS posted:

What do you guys think of the perl 6 logo?
It took me 5 minutes of staring at it and reading the description to figure out what the gently caress i am looking at. Imo the logo should be like good code: Easily recognizable. Larry's logo isn't by virtue of being a complete visual clusterfuck.

Maybe he should let a real graphical designer trim it down to the essentials.

Rohaq
Aug 11, 2006
In fact, not trying to be mean here, but I think that this Dilbert strip illustrates the point well:


Click here for the full 725x524 image.


Get graphic designers to design logos; there is a reason that good ones can make a good living from these things.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
The logo is a bikeshed. Larry should kill himself based off that butterfly alone. Both are terrible but obviously Sri's is yards less terrible.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Rohaq posted:

but it stands for 'Practical Extraction and Report Language'

This was made up wayyyyyyy after the language existed btw

TiMBuS
Sep 25, 2007

LOL WUT?

Triple Tech posted:

The logo is a bikeshed.

well its the only p6 related 'issue' at the moment really, and it is sort of important in a way.
perl 6 needs to get people interested in it, since it's "'new'" (excessive quotation marks necessary). The logo gives a good first impression of the effort put into the language and i dunno if camelia reflects that. Check out http://perl6.org to see what I mean.

TiMBuS
Sep 25, 2007

LOL WUT?

Rohaq posted:

It stands for 'Practical Extraction and Report Language'

sorry but larry says it stands for Pathologically Eclectic Rubbish Lister

Erasmus Darwin
Mar 6, 2001

TiMBuS posted:

perl 6 needs to get people interested in it, since it's "'new'" (excessive quotation marks necessary). The logo gives a good first impression of the effort put into the language and i dunno if camelia reflects that.

It's having the complete opposite effect on me. That abomination of a logo has been the first thing to make me seriously wonder about how well the 5.x branch will continue to be maintained after Perl 6 goes live.

I suppose the second logo's decent, but after seeing the first logo, it becomes a lot harder to accept any logo with a butterfly in it. Because I know when I turn my back, it'll transform back into technicolor vomit and try to eat my brain.

I just don't get it. I don't understand how any rational, sane human being can look at that logo and say, "This is a good idea." I really don't understand how any rational, sane human being can look at that logo and say, "Not only is this a good idea, but here's a detailed breakdown why it's good." It makes me question Larry Wall's judgment on a fundamental level. Is he starting to suffer from dementia? Was he emotionally crippled by some sort of horrific personal tragedy that's left him yearning for the simplicity of his childhood? Did he suffer a severe blow to the head?

Hell, look at the logos for projects that're geared specifically toward children and students (Scratch and Alice, for example). Camelia makes those look grown-up in comparison. There's fun, and then there's trying to pass off something that even Fisher Price would have rejected as too childish.

I didn't mean for this to devolve into a rant like that. I'm just shocked that people are taking the logo seriously.

Erasmus Darwin fucked around with this message at 18:01 on Jun 30, 2010

tef
May 30, 2004

-> some l-system crap ->
Have you seen larry wall?

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

Erasmus Darwin posted:

I don't understand how any rational, sane human being can look at that logo and say, "This is a good idea."
He's a linguist and a programmer, not a designer. Programmer art is not terrible without reason.

Erasmus Darwin
Mar 6, 2001

Mithaldu posted:

He's a linguist and a programmer, not a designer. Programmer art is not terrible without reason.

The problem isn't the art. It's the endorsement of the art. My art sucks too, but you don't see me coming up with crazy justifications on why my sucky art is actually superior. It's just off the rails nutty.

Ninja Rope
Oct 22, 2005

Wee.
My biggest problem with the logo is this:

perl6.org posted:

Hi, my name is Camelia. I'm the spokesbug for Perl 6, the spunky little sister of Perl 5.

I think personifying a logo and having it "talk" to users is too childish, perhaps even creepy. Programming languages don't need to be playful or fun and I think it gives off the wrong impression. Text like the above impedes access to the information users actually want by making them filter through unrelated chatter from the "spokesbug". It also makes promoting perl6 as a serious language alternative harder when the logo looks like something targeted towards children and the websites feature text "written" in first person by a butterfly. A programming language doesn't need a logo, but if it has one it should be unintrusive and only really used to help users identify information related to that language. I don't need to play with it.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

Erasmus Darwin posted:

That abomination of a logo has been the first thing to make me seriously wonder about how well the 5.x branch will continue to be maintained after Perl 6 goes live.

Huh? What does Perl 6's logo have to do with Perl 5?

Erasmus Darwin
Mar 6, 2001

Filburt Shellbach posted:

Huh? What does Perl 6's logo have to do with Perl 5?

Because if the Perl 6 logo is in any way representative of the quality of the Perl 6 project itself, I think I'm going to be sticking with Perl 5 for a long, long time.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
Oh okay, I interpreted it the other way around because I am a moron.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
Well, the 5.10 and 5.12 releases were the beginning (hopefully just the beginning!) of a conscious revitalization of Perl 5's core development.

As an aside, I kind of wish a different tack had been taken for the development model of Perl 6, that was more incremental rather than having apocalypses etc released followed by a small number of folks able to give feedback on the blead of pugs or rakudo at any given time :( I understand for technical reasons this may have been very difficult or impossible, but half the time it seems like the best way to play with Perl 6 features, see what's cool, what should be considered, and what should be tossed is to make or wait for an analogous Moose extension to be made :/

TiMBuS
Sep 25, 2007

LOL WUT?

Otto Skorzeny posted:

Well, the 5.10 and 5.12 releases were the beginning (hopefully just the beginning!) of a conscious revitalization of Perl 5's core development.

As an aside, I kind of wish a different tack had been taken for the development model of Perl 6, that was more incremental rather than having apocalypses etc released followed by a small number of folks able to give feedback on the blead of pugs or rakudo at any given time :( I understand for technical reasons this may have been very difficult or impossible, but half the time it seems like the best way to play with Perl 6 features, see what's cool, what should be considered, and what should be tossed is to make or wait for an analogous Moose extension to be made :/

Agreed. but the rakudo devs know this. they release a binary every month to help potential testers, and a 'try perl6 in a browser' page is halfway made (i got to test it yesterday.. its nice (again, a bit kiddy lookin with the colours))

you know of any other ways to make perl6 easier to try out?

Erasmus Darwin
Mar 6, 2001

TiMBuS posted:

you know of any other ways to make perl6 easier to try out?

Out of curiosity, I dumped "perl 6 download" into Google to see how tricky the situation is. First, a disclaimer: While I point out areas that could be changed to increase the visibility and accessibility of Perl 6, this shouldn't be considered a major criticism. All things considered, the process to install Perl 6 doesn't seem to be too bad (though I didn't get past just looking at pages, so there may be further install issues).

A few observations:

The first hit is the perl.com download page which seems to be Perl 5 only. There's no mention of Perl 6 at all, even as a development/unsupported/bleeding edge branch. In contrast, here's the Python download page, which gives a more prominent position to the better established 2.x branch (including directing new users towards it) but keeps the 3.x branch visible.

As a side note, doing a search for '"perl 6" download' (i.e. with proper quotes) still returns the perl.com page as the first hit.

The second hit is the perlfoundation.org page for downloading Perl 6. This looks to be the right destination (or at least the next hop that ultimately leads to the destination). It looks like a thrown together wiki page. Not exactly the sort of thing that screams "The future of Perl 6 is here." It could be worse (*cough*Camelia*cough*), but it could also be a lot nicer.

Beyond the aesthetics, the page is a bit rough on a new user. If you assume minimal knowledge (User knows what Perl is, User knows Perl 6 is in development), it wants to send them to read a whole shitload of background material on the Perl 6 situation via the "read about them" link. The upside of that link is that it does clarify the whole Perl 6 situation. The downside is that it's full of a lot of stuff that's unnecessary for someone interested in taking a peek at Perl 6. I can appreciate the desire to encourage a variety of implementations by not dubbing an official implementation, but making Rakudo into the wink-wink-nudge-nudge main implementation is just going to bog down end users.

Anyway, the next step a user would follow is to the Rakudo Perl 6 download page. At this point, we hopefully haven't lost the user since "Rakudo" makes it sound like a side-project or fork which may make them give up. Once we're at this page, the user's getting close. For Linux and FreeBSD users, it looks like there are a number of nice packages. A monthly build schedule for pre-built binaries is reasonable. Bonus points for providing a relatively simple means for users to get bleeding edge repository source code, as well.

There are, however, a few short-comings on this page. The Win32 version involves jumping through a couple small hoops (go to a separate project page and download multiple files with some confusing labels). It's not insurmountable, especially when the target audience is programmers, but it does involve making the user puzzle over things that they shouldn't have to puzzle over. On the Linux front, Debian, Ubuntu, and RHEL/CentOS are noticeably missing from the pre-built packages. Finally, if they really wanted to go for extra credit, they could provide a VM image to let people try out Perl 6 with a minimum of hassle. Yes, it's a bit of a waste of bandwidth, but it's a lot better than wasting time.

Anyway, as I said before, the download situation isn't intolerable, but there is room for streamlining things for the user. These are just my observations as someone who hasn't really been following Perl 6.

TiMBuS
Sep 25, 2007

LOL WUT?

Erasmus Darwin posted:

<cool stuff>
Anyway, as I said before, the download situation isn't intolerable, but there is room for streamlining things for the user. These are just my observations as someone who hasn't really been following Perl 6.

Thanks for all this. Reported it all to the perl6 guys. I havent gotten around to reporting back all the camelia hate yet because im waiting for a more oppertune time when the devs arent too busy worrying about the current lazy list implementation

Erasmus Darwin
Mar 6, 2001

TiMBuS posted:

Thanks for all this. Reported it all to the perl6 guys.

Cool. Out of curiosity, I did try installing Perl 6 last night in order to see what was involved. It turns out all I needed to do was "su -c 'yum install rakudo'" on a fresh Fedora VM.

I didn't bother trying the Windows version, but the Parrot Win32 download page makes a lot more sense this morning. It seems the two downloads one would need would be the big green button (setup-parrot-2.5.0.exe) plus "parrot-rakudo addon/Parrot-2.5.0-Rakudo-30/setup-parrot-2.5.0-rakudo-30.exe" (which is also currently at the top of the file list highlighted in green).

I think the thing that threw me last time is that my eyes were drawn to the green bar for the setup-parrot-2.5.0-rakudo-30.exe (where it appeared as the newest file), and I was trying to compare it to itself (where it appeared with its full path under "parrot-rakudo addon"). It also didn't help that the page loaded slowly (which caused a bunch of extra files to show up before being hidden in subfolders by javascript), and I was also trying to puzzle out the addon numbering scheme at the same time (which seems to intermix two-digit release numbers and eight-digit YYYYMMDD timestamps).

At the end of the day, it all makes sense, it just a few extra things to puzzle out.

Marzzle
Dec 1, 2004

Bursting with flavor

code:
$workdir =~ /[\W|\s|_]*(R40|GG1|EC|WT4)[\W|\s|_]([1-5][\W|\s|_|.][1-5]|[1-5])[\W|\s|_]*(r|f)*/i;
        $indv = $1;
        $plate = $2;
        $direction = $3;
for some reason on a foreach loop on this regex the $2 capture is never set to uninitialized while the $3 consistently is. I would like to just reset all the capture variables to uninitialized on each loop but after much searching it doesn't seem like a thing. What is so special about the $2? I just want it to change to uninitialized when it isn't found :(.

Erasmus Darwin
Mar 6, 2001

Marzzle posted:

What is so special about the $2? I just want it to change to uninitialized when it isn't found :(.

The way your regexp is written, it looks like the $2 group is non-optional. So if there's nothing for $2 to match, the entire regexp will fail. Did you mean to stick a '?' or '*' in there as a modifier for $2?

Marzzle
Dec 1, 2004

Bursting with flavor

Unfortunately it's one of the 2nd regexp"ies" that I've written. Here's the entire code:

code:
#!/usr/bin/perl -w
use strict;

my @output;
my @topdir;
my $test;
my $workdir;
my $indv;
my $plate;
my $direction;
my @files;
my $well;
my $n=0;

$workdir = shift; #implied shift on @ARGV
chdir $workdir; #now in dir specified in @ARGV

@topdir = `ls`;

foreach(@topdir) #this moves through each dir and then back up again...
{
    $n = $n + 1;
    print "$n\n";
    #print "initial plate = $plate\n";
    
    
    $workdir = $_; #$_ dennotes the current element of @ the foreach is on

    print "workdir = $_";

    chomp ($workdir); #directory needed to be chomped to be passed to chdir, why?
    #print "plate before regex $plate\n";
    #print "direction before regex $direction\n";
    $workdir =~ /[\W|\s|_]*(R40|GG1|EC|WT4)[\W|\s|_]([1-5][\W|\s|_|.][1-5]|[1-5])[\W|\s|_]*(r|f)*/i;
        $indv = $1;
        $plate = $2;
        $direction = $3;
        #print "plate after regex $plate\n";
        #print "direction after regex $direction\n";
        if (defined($indv) and defined($plate) and defined($direction))
        {
            chdir ( $workdir );
            print "Type 1\n";
            print "indv = $indv\n";
            print "plate = $plate\n";
            print "direction = $direction\n\n";
            @files = `ls`;
        
            foreach(@files)
                {
                    $_=~s/GG1//i;
                    $_=~/([0|1]*[0-9][a-h]{1}|[a-h]{1}[0|1]*[0-9])[\b|\W|\s|_|.]/i;
                    $well=$1;
                    print "$_";
                    print "$well\n\n"
                }
            print "\n";
        }
     
        elsif (defined($indv) and defined($plate))
        {
            chdir ( $workdir );
            print "type 2\n";
            $direction = 'nodir';
            print "indv = $indv\n";
            print "plate = $plate\n";
            print "direction = $direction\n\n";
            @files = `ls`;        
            foreach(@files)
                {
                    print "$_";
                    $_=~s/GG1//i;
                    $_=~/([0|1]*[0-9][a-h]{1}|[a-h]{1}[0|1]*[0-9])[\b|\W|\s|_|.]/i;
                    $well=$1;
                    print "$_";
                    print "$well\n\n"
                }
            print "\n";
        }
     
        elsif (defined($indv))
        {
            chdir ( $workdir );
            print "type 3\n";
            $direction = 'nodir';
            $plate = 'noplate';
            print "indv = $indv\n";
            print "plate = $plate\n";
            print "direction = $direction\n\n";
        }
        
    chdir '..'; #moving back up
}


SO if you don't want to read all that, I was under the impression that if a group doesn't match then the $2 is just set to uninitialized much like $3 is set to if the group isn't matched. I am very new to all this so I am sure I am loving the whole thing up but the $# vars are all read only so I can't seem to reset them by hand.

Why is $3 uninitializing upon not finding anything but $2 isn't? The whole loop is working great except when a $2 gets passed on from the previous part to the next part of the foreach...

Ultimately the script is supposed to move the files around and rename them in a sane way but I am just printing the output to the terminal for now.

Any other criticism is appreciated. I literally learned to program this stuff a week ago so I am sure there's other points I am off on.

Specifically what do you mean about using '?' or '*' as modifiers for groups? I was under the impression that /(...)/ means you always get a $1 equal to ... . Is there something I am missing?

Erasmus Darwin
Mar 6, 2001

Marzzle posted:

Specifically what do you mean about using '?' or '*' as modifiers for groups? I was under the impression that /(...)/ means you always get a $1 equal to ... . Is there something I am missing?

Let's boil it down to a much simpler regexp.

$foo =~ /^(a)(b)?$/;

Because there's a ? after (b), that means that part's optional. The regexp will match strings that always start with exactly 1 'a' followed by 0 or 1 'b'. So it'll match:

'a' -> $1 set to 'a', $2 undefined
'ab' -> $1 set to 'a', $2 set to 'b'

If you try and match a string consisting of just 'b', the regexp will fail to match because the regexp requires the 'a' to be there. So ($foo =~ /^(a)(b)?$/) evaluates to false and $1 and $2 retain their previous values.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?

Marzzle posted:

Any other criticism is appreciated. I literally learned to program this stuff a week ago so I am sure there's other points I am off on.
From a quick once-over:
  • Too many global variables (KISS)
  • Don't use shift() on @ARGV or @_ unless you know you need to
  • You can move those two inner foreachs into a single sub (DRY)
  • This may be a matter of personal preference but I shudder when seeing more than one/two levels of nested blocks (e.g. a foreach inside an if inside another foreach)
  • Don't need to call ls using backticks, just use something like File::Glob, which is a core module

Roseo
Jun 1, 2000
Forum Veteran
What are some examples of your working set? The regexes, in particular the one you're having issues with, seem somewhat unnecessary and could potentially be replaced with a split.

Instead of:
code:
foreach (@foo) {
  my $bar = $_;
}
Assign it in your loops:
code:
for my $bar (@foo) {
  ### Work with $bar here
}
There's a few places where hashes could improve the legibility of your code. ie, something like...

code:
$indv = $1;
$plate = $2;
$direction = $3;

print "Type 1\n";
print "indv = $indv\n";
print "plate = $plate\n";
print "direction = $direction\n\n";


### Associate related data into a single variable, a hash...
my %item;
$item{indv} = $1;
$item{plate} = $2;
$item{direction} = $3;

print "Type 1\n";
for my $value (qw/indv plate direction/) {
  print "$value = $item{$value}\n"
}
print "\n";


### Or condense even more with hash slices and map...
### Don't worry about writing stuff like this quite yet though.
my %item;
@item{qw/ indv plate direction/} = ($1, $2, $3);
print map {"$_ = $item{$_}\n"} qw/ indv plate direction/, "\n";
Lastly, use warnings, it'll keep you from falling into bad habits.

Roseo fucked around with this message at 07:14 on Jul 7, 2010

Adbot
ADBOT LOVES YOU

JawnV6
Jul 4, 2004

So hot ...
The pattern I always use is this:
code:
if( $string =~ /regexp/i ) {
  $name = $1;
  $plate = $2;
}
You're not checking if the regular expression matched, you're just indenting after the =~ with no handling if it doesnt match :psyduck:. So when you would see $1 and $2 defined and not $3, it means the regular expression failed and $1/$2/$3 are the results from one of the regexes further down in the program.

  • Locked thread