Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I still think something is wrong...

If I do something like:
mkdir dir1 dir2 touch dir1/f{1,2}
and then run:
foreach (1,2,3,4) { print "dir1\n" if glob("dir1/f*"); print "dir2\n" if glob("dir2/f*"); }
I get 'dir1' printed 3 times (NOT 4). But if I unwind the loop:
print "dir1\n" if glob("dir1/f*"); print "dir2\n" if glob("dir2/f*"); print "dir1\n" if glob("dir1/f*"); print "dir2\n" if glob("dir2/f*"); print "dir1\n" if glob("dir1/f*"); print "dir2\n" if glob("dir2/f*"); print "dir1\n" if glob("dir1/f*"); print "dir2\n" if glob("dir2/f*");
Then I get 'dir1' printed 4 times!!!

In other words, I can understand why 'glob' is stateful when it is the loop iterator. But it makes no sense (to me) (and seems wrong) for it to be stateful when it is not the iterator. Because then unwinding a loop give a different answer.

In reply to Re^4: Using grep and glob to find directories containing file by Anonymous Monk
in thread Using grep and glob to find directories containing file by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    [Eily]: well, at least it's right about warn doing the same thing as die :)
    [shmem]: same with undef as last element
    [msh210]: oh, good point. It's the best kind of correct
    [shmem]: msh210: but I'd not call it a lie outright. That's when you do know the truth.
    [msh210]: I don't have sendmail (I'm on MS Windows), so does one of you think you can report the bug?
    [shmem]: msh210: 'tis about time to tell the sad truth to perl5porters - via perlbug
    [msh210]: probably whoever wrote that actually knows the truth
    [shmem]: msh210: you can save the perlbug text in a file and send that via your mail agent of choice
    [msh210]: hm, okay, I'll try, thanks
    [shmem]: ...not as an attachment, it's probably better to c&p that into the mail body

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (15)
    As of 2017-04-24 12:45 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      I'm a fool:











      Results (439 votes). Check out past polls.