Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: Another newb question

by AnomalousMonk (Archbishop)
on Aug 08, 2012 at 10:43 UTC ( [id://986219]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Another newb question
in thread Another newb question

But all the Perls I have in captivity recognize a syntax error for the line missing the semicolon, although they make no mention of the semicolon itself.

>perl -le "use warnings ; use strict ; print \"This program will display ... when done.\n\" my @userin = <STDIN> ; printf \"%-20s\", @userin ; " syntax error at -e line 1, near ""This program will display ... when d +one.\n" my " Global symbol "@userin" requires explicit package name at -e line 1. Global symbol "@userin" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors.

If my own experience is any guide, what happened is that Parmenides, momentarily unable to interpret the first (and critical) error message, was drawn to concentrate on the subsequent 'error' message unaware that it was entirely an artifact of the preceding error. A very common oversight (again, IME). The lesson: Pay strict attention to the point at which the compiler first stumbles and don't be distracted by the point at which it finally bites the dust.

Replies are listed 'Best First'.
Re^4: Another newb question
by davido (Cardinal) on Aug 08, 2012 at 16:32 UTC
Re^4: Another newb question
by dasgar (Priest) on Aug 09, 2012 at 03:54 UTC

    Well, I didn't actually run the code myself. Thought I'd share what I did in case it helps others.

    I just cut and pasted the OP's code into Padre. It marked the last two lines of code as having issues. When I moved my mouse over the next to last line, Padre showed the same error message that the OP listed. However, that line looked correct to me.

    Here's the key part. From past experience, I figured that if the line that is indicated as having issues by the Perl interpreter, then I needed to check the line(s) before it. In my code, the cause has usually been missing semi-colon or I had opened a closure (single quotes, double quotes, square bracket, etc.) and failed to close the closure. Those two kinds of mistakes usually has caused the Perl interpreter to complain about an incorrect line number in my code.

    Anyways, when I started checking the other lines of code, that's when I noticed the missing semi-colon.

Re^4: Another newb question
by Parmenides (Novice) on Aug 08, 2012 at 22:30 UTC

    @everybody, Thanks for all the help!

    @#333 I don't think I missed an error but it's certainly possible

    Hopefully, this is my final question. When I print my array with printf each string should be printed in a right justifified 20 character column (i.e. the last letter should be indented 20 characters sort of like align left in word.) As per the book's request I created a ruler line to determine how far the last character was actually being indented and it is only being indented 19 characters. I can not figure out why. Any help would be appreciated. Thanks!

    #!/usr/bin/perl use warnings ; use strict ; print "This program will display what you type in right justified 20 c +haracter columns.\nEnter text and press ctrl + d when done.\n" ; my @userin = <STDIN> ; print "1234567890" x3 ; foreach (@userin) { printf "%20s", $_ ; }

      Since you're reading in from STDIN, you might need to use chomp on the last element of your array.

      I haven't tested it, but you might be able to modify your foreach loop to something like below, which uses chomp on each element.

      foreach (@userin) { chomp; printf "%20s", $_ ; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-20 05:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found