Rookie question: code works after adding a "print" statement

  • Thread starter Charles Fitzgerald
  • Start date
C

Charles Fitzgerald

Given the data file beloe (it's a "flattened" AIX /etc/security/passwd
file)
I am attempting to split it into its component parts. The following
yields an error:

#!/usr/bin/perl
while (<STDIN>) {
do
########print;
($username, @therest ) = split /:/,$_;
print $username,"\n";
done
}
The error messages is:

Too many arguments for do "file" at ./newhash line 5, near ") ="
Execution of ./newhash aborted due to compilation errors.

Uncommenting the print; statement makes it work. WHY??!?

Please
root: + password = abcabcabcabca + lastupdate =
1066703040 + flags = +
daemon: + password = * +
bin: + password = * +
sys: + password = * +
adm: + password = * +
uucp: + password = * +
nobody: + password = * +
lpd: + password = * +
mike: + password = abcabcabcabcA + lastupdate = 1030991397
+ flags = ADMCHG +
darren: + password = abcabcabcabca + lastupdate = 969316376
+ flags = +
ron: + password = abcabcabcabca + lastupdate = 983309074 +
flags = +
 
T

Tony Curtis

On 5 Apr 2004 17:47:38 -0700,
Given the data file beloe (it's a "flattened" AIX
/etc/security/passwd file) I am attempting to split it into
its component parts. The following yields an error:
#!/usr/bin/perl
while (<STDIN>) {
do
########print;
($username, @therest ) = split /:/,$_;
print $username,"\n";
done
}
The error messages is:
Too many arguments for do "file" at ./newhash line 5,
near ") =" Execution of ./newhash aborted due to compilation
errors.

do...done? This ain't the Bourne shell! :)

perldoc -f do

Don't forget to add

use strict;
use warnings;

after the shebang.

hth
t
 
U

Uri Guttman

CF> Given the data file beloe (it's a "flattened" AIX /etc/security/passwd
CF> file)
CF> I am attempting to split it into its component parts. The following
CF> yields an error:

CF> #!/usr/bin/perl
CF> while (<STDIN>) {
CF> do
CF> ########print;
CF> ($username, @therest ) = split /:/,$_;
CF> print $username,"\n";
CF> done
CF> }

where did you learn that do/done syntax? it is not perl.

perl has do (three kinds!!) but none like that. done isn't even a
keyword in perl.

uri
 
C

Charles Fitzgerald

Uri Guttman said:
CF> Given the data file beloe (it's a "flattened" AIX /etc/security/passwd
CF> file)
CF> I am attempting to split it into its component parts. The following
CF> yields an error:

CF> #!/usr/bin/perl
CF> while (<STDIN>) {
CF> do
CF> ########print;
CF> ($username, @therest ) = split /:/,$_;
CF> print $username,"\n";
CF> done
CF> }

where did you learn that do/done syntax? it is not perl.

perl has do (three kinds!!) but none like that. done isn't even a
keyword in perl.

uri

Dohp!

I came back and looked at the code later this evening and spotted the
do...done syntax myself. I'd been Korn scripting all day when I
started messing with this. I popped in here to cancel the post (and
maybe save some embarrassment), but no such luck. That's what happens
when you've been looking at a bit of code too long. Sometimes walking
away is the most productive move!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,132
Latest member
TeresaWcq1
Top