softworkz has asked for the wisdom of the Perl Monks concerning the following question:

Help... :( Why doesn't this work? I'm at wits end here!
Each time I run it I get 0:20:00 isn't numeric? Thanks!
while (<FILE>) { chomp; # sample line is like # Tz25 ATHENA01 0:20:00 my $user; my $node; my $hour; my $min; my $sec; my $line = $_; $line =~ tr/:/ /; # tried this also $line =~ s/:/ /g; push my @users, $line; # here it's Tz25 ATHENA01 0 20 00 ($user, $node, $hour, $min, $sec) = @users = split(/ /); # now if I do an lt here it doesn't complain? # but that would be based off 0:20:00 if ($hour < 24){ print $user," ", $node," ", $hour; print CLU $user," ", $node," ", $hour; }

Replies are listed 'Best First'.
Re: pattern matching
by dragonchild (Archbishop) on Sep 06, 2001 at 22:04 UTC
    You're putting the translated value into $line, but doing the split on $_.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Vote paco for President!

Re: pattern matching
by blakem (Monsignor) on Sep 06, 2001 at 22:06 UTC
    Two things...
    push my @users, $line;
    Is better written as either:
    push my(@users), $line;
    OR
    my @users; push @users, $line;
    But your error is being caused because split using the default value in $_ instead of $line. Instead try:
    split(/ /,$line)

    -Blake

      >> push my(@users), $line; # or even more straightforward: my @users = ($line);
      But I don't see the point of @users anyway. First, its misnamed. It doesn't really contain 'users', it contains data for one 'user'. You're setting it to '($line)' then resetting it on the very next line. If you really mean to collect 'users' in this array, then you wouldn't use my on the push statement, but you'd declare (my) '@users' in an outer block somewhere.
        I guess you're right... If you're using my to declare it immediately beforehand, push is the same as assignment.

        I don't know the use for @users either, but the code snippet above is a non-balanced fragment:

        while(<FILE>) { my @users; [snip] if ( [snip] ) { [snip] } # @users is still in scope as we fall off the end....
        Therefore, perhaps there is a use for it outside of the window we've been shown.

        Looking at it a second time, @users should probably be scoped outside the while, since it is most-likely supposed to be an array of slightly munged lines from the file.

        -Blake

      Thanks! That was the problem :( walks away with his head down with embaressment.