in reply to sytem command perl

Because you have to quote strings
system q(perl -pi -e 's/>//g' filename);

Replies are listed 'Best First'.
Re^2: sytem command perl
by massa (Hermit) on Aug 25, 2008 at 09:43 UTC
    better yet, quote each string argument:
    system 'perl', '-pi', '-e', 's/>//g', $filename;
    See? I didn't quote $filename because the variable is already the argument I want to pass to 'perl'.
    But you can even do better: instead of calling another instance of perl, do the job right here:
    CHANGE_FILE: { my $backup = "${filename}~"; rename $filename, $backup; open my $b, '<', $backup; open my $f, '>', $filename; select $filename; s/>//g, print while <$backup> }
    []s, HTH, Massa (κς,πμ,πλ)
      • You should check that open, close & rename succeeded
      • If you're going to use select (and I wouldn't) make sure to restore STDOUT to what it should be when you're finished with it
      • You've confused the use of $filename, $f, $backup and $b in your last two statements.
Re^2: sytem command perl
by deepjyot (Initiate) on Aug 25, 2008 at 05:21 UTC
    system q(perl -pi -e 's/>//g' $filename); If i use a scalar variable instead of the filename or an entire directory then the system hangs... system q(perl -pi -e 's/>//g' $dirname/*); doesn't work.... plz help....