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

Discussion in 'Perl Misc' started by Charles Fitzgerald, Apr 6, 2004.

  1. 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 = +
     
    Charles Fitzgerald, Apr 6, 2004
    #1
    1. Advertising

  2. Charles Fitzgerald

    Tony Curtis Guest

    >> On 5 Apr 2004 17:47:38 -0700,
    >> (Charles Fitzgerald) said:


    > 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
     
    Tony Curtis, Apr 6, 2004
    #2
    1. Advertising

  3. Charles Fitzgerald

    Uri Guttman Guest

    >>>>> "CF" == Charles Fitzgerald <> writes:

    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

    --
    Uri Guttman ------ -------- http://www.stemsystems.com
    --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
    Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
     
    Uri Guttman, Apr 6, 2004
    #3
  4. Uri Guttman <> wrote in message news:<>...
    > >>>>> "CF" == Charles Fitzgerald <> writes:

    >
    > 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!

    --
    Misterfitz is a spam trap.
     
    Charles Fitzgerald, Apr 6, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. keto
    Replies:
    0
    Views:
    957
  2. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    358
    David Cournapeau
    Dec 30, 2008
  3. sdfgsd
    Replies:
    6
    Views:
    200
    sdfgsd
    Oct 9, 2003
  4. sdfgsd
    Replies:
    10
    Views:
    239
  5. Replies:
    0
    Views:
    269
Loading...

Share This Page