in reply to Re: special pattern reading
in thread special pattern reading

Why is my version not working?

use strict; use warnings; { my $input = do { open my $in, '<', '1.txt'; local $/; <$in> }; until ( eof $in){ my $file = <$in>; $file =~ s/..![^!]*something.*\.c//; print $file . "\n"; }

Replies are listed 'Best First'.
Re^3: special pattern reading
by hippo (Archbishop) on Jan 13, 2016 at 10:32 UTC

    Your code doesn't compile:

    $ perl -cw 1152653.pl Global symbol "$in" requires explicit package name at 1152653.pl line +9. Global symbol "$in" requires explicit package name at 1152653.pl line +11. Missing right curly or square bracket at 1152653.pl line 14, at end of + line syntax error at 1152653.pl line 14, at EOF 1152653.pl had compilation errors.

    You'll need to fix the errant opening brace and the scoping of $in.

    Update: Here's a working rewrite of your script above:

    use strict; use warnings; open my $in, '<', '1.txt' or die "Cannot open 1.txt: $!"; while (my $file = <$in>) { $file =~ s/..![^!]*something.*\.c//; print $file; } close $in;

    And here's what happens when I run it:

    $ cat 1.txt foo ?!?!?!/pack/something/whatever.cacshdska bar $ perl fixup.pl foo ?!?acshdska bar