Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Why can't I open a file for writing?

by haukex (Abbot)
on Jan 13, 2018 at 09:09 UTC ( #1207190=note: print w/replies, xml ) Need Help??


in reply to Why can't I open a file for writing?

Something I noticed in addition to the comments about open ... or die:

my $dir = '/some/directory/here'; my @files = <$dir/\d{6}*>; # All the relevant files start with 6 numbers, so don't glob others!

Sorry but I don't see how the pattern <$dir/\d{6}*> can be working at all* - glob does not recognize regex syntax, unless you're using some custom module. Always Use strict and warnings - you should be seeing a warning like "Unrecognized escape \d passed through".

Also, be very careful with what $dir contains, and in fact with glob in general, as discussed in the recent thread To glob or not to glob.

* Update: Or rather, how it is working in the context provided, "All the relevant files start with 6 numbers" - thanks for pointing this out, Lotus1!

Replies are listed 'Best First'.
Re^2: Why can't I open a file for writing?
by Lotus1 (Curate) on Jan 13, 2018 at 16:49 UTC

    Like you said there will be a warning but the pattern will match files. It matches files starting with 'd6' with any number of characters after it. I imagine the next question after fixing the file open issue would have been 'why are only some files being opened?'

    use warnings; use strict; use v5.10; say foreach glob("\d{6}*"); __END__ Unrecognized escape \d passed through at globmeta.pl line 5. d60000000000b.txt d600.txt

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1207190]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2018-01-21 02:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (227 votes). Check out past polls.

    Notices?