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

ERROR -> Scalar found where operator expected at test.pl line 13, near "$result" (Missing semicolon on previous line?) syntax error at test.pl line 13, near "$result
#!/usr/bin/perl my $frompath = "/home/scr"; my $topath = "/home/scr"; chomp(@mypath = `ls $frompath/DVD*/Packages/*.tar`); my $mycwd=`pwd`; foreach $test (@mypath) { if ($test =~ m/(DVD\d)/ ) { my $toloc = "$topath/$1/Packages"; "chdir $toloc or dir qq(can't chdir $toloc $!\n);" my $result = `/usr/bin/tar -xvpf $test`; } } "chdir $mycwd or dir qq(can't chdir $toloc $!\n);"

Replies are listed 'Best First'.
Re: What is wrong with tar?
by alienhuman (Pilgrim) on Mar 22, 2006 at 01:02 UTC

    UPDATE: s/single quotes/backticks/ and oops, chdir is a perl func... /me face red

    Hey,

    That error message is telling you "missing semicolon on previous line". So if you go to line 13, then back up one line you find the problem line:

    12:--> "chdir $toloc or dir qq(can't chdir $toloc $!\n);" 13: my $result = `/usr/bin/tar -xvpf $test`;
    You don't have a semicolon at the end of that line. You've got a quoted string ("chdir... );") with no semicolon.

    Also, you've misspelled die as "dir". You want something like:

    chdir $toloc or die qq(can't chdir $toloc $!\n);

    Hope this helps you the next time you have perl complaining about some error--now you know how to find more-or-less where your error is.

    AH

    p.s. I'll let someone else give the standard use strict and warnings speech.

    ----------
    Using perl 5.8.6 unless otherwise noted. Apache/2.0.54 unless otherwise noted. Fedora Core 4 (2.6.11-1.1369_FC4) unless otherwise noted.