Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: strict

by arturo (Vicar)
on Feb 02, 2001 at 01:30 UTC ( [id://55846]=note: print w/replies, xml ) Need Help??


in reply to strict

That's because you're not declaring your variables, as strict forces you to do.

You need to add:

my $line; my @lines;

BEFORE you try to set them, for your code to work. Alternately, omit the FIRST of the declarations above and change that one line to while (my $line = <> ...)

Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Replies are listed 'Best First'.
Re: Re: strict
by snowrider (Pilgrim) on Feb 02, 2001 at 01:42 UTC
    i can make the program work when i use
    my $line; my @lines;
    but i cant seem to make
    #!/opt/perl5/bin/perl -w use strict; #my $line; my @lines; while(my $line=<> and $line ne ".\n"){ push @lines,$line; } foreach(reverse @lines){ print; }
    work am i doing something wrong?? i keep getting this error
    Global symbol "$line" requires explicit package name at day1_test.1.pl + line 8. Value of <HANDLE> construct can be "0"; test with defined() at day1_te +st.1.pl line 8. Execution of day1_test.1.pl aborted due to compilation errors.
    snowrider

      Whoops. The problem is that the second way I gave you won't work because the my $line part of it will fail -- and the variable won't be declared -- if you read in a blank line from the file you're looking through. So you could get a loop with the same logic by changing it to:

      while (my $line = <> ) { push @lines, $line unless $line eq ".\n"; }

      HTH

      Philosophy can be made out of anything. Or less -- Jerry A. Fodor

        thank you you have been a big help!! snowrider

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://55846]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-18 00:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found