Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: using strict

by tcf22 (Priest)
on Mar 22, 2004 at 20:56 UTC ( #338763=note: print w/ replies, xml ) Need Help??


in reply to using strict

It is because you are using "$recno^$qno^$vtext"; in your print statement, but they aren't declared in the block.

For Example:

my $a = <STDIN>; if($a eq 'y'){ my ($fname, $lname) = ('tom', 'test'); print "$fname $lname\n"; #OK because vars declared in block } print "$fname $lname\n"; #Vars are out of scope now, will die under st +rict


Your code should look something like this, so your vars can be used between loop iterations.
#!/usr/bin/perl use strict; use warnings; open (IN, "infile") or die "Can't open input file: $!\n"; open (OUT, ">outfile") or die "Can't create outfile for write: $!\n "; my ($junk,$qno,$junk2,$vtext,$recno); while (<IN>) { if (/^##recstart/) { ($junk,$recno) = split; $recno =~ s/'//g; }elsif (/^##v/) { ($junk,$qno,$junk2,$vtext) = split (/ /,$_,4); $qno =~ s/'//g; $vtext =~ s/'//g; }else { print OUT "$recno^$qno^$vtext"; } }

- Tom


Comment on Re: using strict
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2015-07-03 22:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls