aridzonan has asked for the wisdom of the Perl Monks concerning the following question:

#/usr/bin/perl # Cosmo Learning File Open operation PERL(II) class lecture. $fname = "/home/jfquaid/bin/PERL/new.txt"; open XYZ, $fname, or die "Error open: $!"; while (<XYZ>) { print "Line number $. ls: $_"; } # Does not farction "line 7: syntax error near unexpected token from s +hell!!`)'
#The above snippet runs in Padre 0.42. However, it crashes with the above commented syntax error from the command line in Ubuntu 9.10 / Kernel 2.6.31-169-generic.. And I believe I'm up to date on all my patches. Any suggestions??

Regards, JQ

Replies are listed 'Best First'.
Re: Syntax Problem / Padre vs Command Line
by ww (Archbishop) on Dec 25, 2009 at 21:15 UTC

    I'm going to have to refresh or deepen my knowledge of the usage of "farction". :-)

    Possibly that's just a typo, in which case, this may be too:

    print "Line number $. ls: $_";
      which may be intended to be:
    print "Line number $. is: $_";

    OTOH, if it's really intended to be ls you may profit by reading about exec, system and backticks.

    Or is there some other typo which merely makes ls appear nonsensical inside double quotes in a print statement?

    Afterthought: Did you intend your script to look like this?

    #!/usr/bin/perl # Cosmo Learning File Open operation PERL(II) class lecture. 814366 $fname = "814366.txt"; open XYZ, $fname, or die "Error open: $!"; while (<XYZ>) { print "Line number $. ls: $_"; } # Does not farction "line 7: syntax error near unexpected token from + shell!!`)'

    If so, as you've been advised, use code tags, or -- more verbosly -- pay attention to the advisories below the text entry box and read Markup in the Monastery.

      For the benefit of all intrigued by OP's problem, he replied to my post above, by private message, thusly:
      aridzonan says Re Re: Syntax Problem / Padre vs Command Line Made the changes you suggested with the same "Unexpecte token" err. Is there an perl enviromental variable that I need to set? Padre has no problem with this bit of code. However, KDevelop, Eric and Shell return the err.

      aridzonan: that doesn't exactly enlighten me on what you did, so perhaps you'll post for the benefit of all of us -- yourself included.

Re: Syntax Problem / Padre vs Command Line
by Anonymous Monk on Dec 25, 2009 at 19:41 UTC
    1. surround your code with <c></c> tags
    2. run programs with perl myfile, see perlrun for more
    3. fix your shebang, its #!/path/to/executable, in case of perl this is good
      #!/usr/bin/perl --