Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: special pattern reading

by hippo (Bishop)
on Jan 13, 2016 at 09:51 UTC ( [id://1152650]=note: print w/replies, xml ) Need Help??


in reply to special pattern reading

If I understand you correctly then this substitution should be all you need for manipulating the filename:

use strict; use warnings; my $file = '?!?!?!/pack/something/whatever.cacshdska'; $file =~ s/..![^!]*something.*\.c//; print $file . "\n";

Replies are listed 'Best First'.
Re^2: special pattern reading
by N0obieMonk (Novice) on Jan 13, 2016 at 10:12 UTC

    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"; }

      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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-03-28 10:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found