[31297] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 2542 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 7 18:09:58 2009

Date: Fri, 7 Aug 2009 15:09:24 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 7 Aug 2009     Volume: 11 Number: 2542

Today's topics:
    Re: issue with multiprocess - fork <hirenshah.05@gmail.com>
    Re: Perl process as a unix background process <jimsgibson@gmail.com>
    Re: Process to upload multiple files from a single <inp <edMbj@aes-intl.com>
    Re: Process to upload multiple files from a single <inp <edMbj@aes-intl.com>
    Re: Process to upload multiple files from a single <inp <edMbj@aes-intl.com>
    Re: Process to upload multiple files from a single <inp <smallpond@juno.com>
    Re: Process to upload multiple files from a single <inp <edMbj@aes-intl.com>
    Re: Process to upload multiple files from a single <inp <ben@morrow.me.uk>
    Re: Process to upload multiple files from a single <inp <smallpond@juno.com>
    Re: Process to upload multiple files from a single <inp <edMbj@aes-intl.com>
    Re: Process to upload multiple files from a single <inp <edMbj@aes-intl.com>
    Re: Process to upload multiple files from a single <inp <ben@morrow.me.uk>
    Re: using file globs and regex <pgodfrin@gmail.com>
    Re: using file globs and regex <pgodfrin@gmail.com>
    Re: using file globs and regex <ben@morrow.me.uk>
    Re: using file globs and regex <smallpond@juno.com>
    Re: using file globs and regex <tadmc@seesig.invalid>
    Re: using file globs and regex <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 7 Aug 2009 12:59:28 -0700 (PDT)
From: "friend.05@gmail.com" <hirenshah.05@gmail.com>
Subject: Re: issue with multiprocess - fork
Message-Id: <31fa603b-eabc-4f0f-a710-11f3905e1ca2@f18g2000prf.googlegroups.com>

On Aug 7, 8:29=A0am, Tad J McClellan <ta...@seesig.invalid> wrote:
> Xho Jingleheimerschmidt <xhos...@gmail.com> wrote:
> > friend...@gmail.com wrote:
> >> My script is using fork so there are child processes. Sometimes my
> >> script runs properly and output is correct. But sometime my script
> >> gets stuck just after exiting child process.
>
> > Asking the same question under a different subject line is more likely
> > to annoy the people you want to help you, than it is to get you more he=
lp.
>
> Indeed, as I had killfiled this OP in April when he crossposted
> the first time.
>
> =A0 =A0http://groups.google.com/groups/search?as_umsgid=3D74405uF119t50U2=
%40mi...
>
> I thought at the time that it was perhaps a bit harsh to banish
> him to perpetual invisibility, but I did it anyway.
>
> Seeing that he still does it after being warned about it makes
> me feel better about my original decision.
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"

sorry about that. I thought it 3days so people might not see the
thread and I am stuck at that problem. so I posted new thread.

will be careful next time


------------------------------

Date: Fri, 07 Aug 2009 12:24:34 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Perl process as a unix background process
Message-Id: <070820091224349513%jimsgibson@gmail.com>

In article
<f6531869-7ac3-462c-9e8c-dafa0b78bf58@l35g2000vba.googlegroups.com>,
<gbostock@excite.com> wrote:

> On Aug 7, 10:16 am, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
> wrote:
> > gbost...@excite.com wrote:
> > > I'm experiencing some strange behavior with a certain perl program
> > > when trying to run it as a unix background process. This process runs
> > > with no problems at the terminal.
> > > When I do:
> > > (prompt)$myperl.pl &
> >


> > > Please don't ask me to post the code as it is proprietary.
> >
> > Instead, you could comment out large chunks of your code to
> > narrow down where it might occur.  Once you narrow it down
> > to the particular line(s), then you can post your short example.
> 
> Narrow it down on what basis? Guessing?

Either educated guessing or just brute force: throw out a line; if the
problem remains, throw out another line and repeat. If the problem goes
away, put back that line and throw out another one. Repeat until only
lines that contribute to the problem remain. Then post those lines.

Educated guessing will allow you to throw out more than one line at a
time, but you are still guessing.

By the time you have completed this process, it is likely that you will
have diagnosed the problem and won't need anybody's help.

-- 
Jim Gibson


------------------------------

Date: Fri, 07 Aug 2009 12:26:26 -0700
From: Ed Jay <edMbj@aes-intl.com>
Subject: Re: Process to upload multiple files from a single <input type=file>
Message-Id: <0tvo75d8abuid9qnk7vnm2s3mvsoldfi3r@4ax.com>

Peter J. Holzer wrote:

>On 2009-08-05 19:23, Ed Jay <edMbj@aes-intl.com> wrote:
>> I have a form that allows multiple files to be selected using a single
>> input element, e.g., <input type='file' min='1' max='999'>,
>
>http://www.w3.org/TR/html401/ doesn't mention any "min" and "max"
>attributes for the input element, and this doesn't seem to let you
>select multiple files in IE7 or FF3.5. In which browser does this work?
>
Opera for certain, and I've read Safari. We supply a customized version of
Opera to our customers, so can rely on the ability to select multiple
files.

-- 
Ed Jay (remove 'M' to reply by email)

Win the War Against Breast Cancer.
Knowing the facts could save your life. 
http://www.breastthermography.info


------------------------------

Date: Fri, 07 Aug 2009 12:30:33 -0700
From: Ed Jay <edMbj@aes-intl.com>
Subject: Re: Process to upload multiple files from a single <input type=file>
Message-Id: <r30p759brq5d1v2pmlgj38tdmrd6f70e9a@4ax.com>

Christian Winter wrote:

>Peter J. Holzer schrieb:
>> On 2009-08-05 19:23, Ed Jay <edMbj@aes-intl.com> wrote:
>>> I have a form that allows multiple files to be selected using a single
>>> input element, e.g., <input type='file' min='1' max='999'>,
>> 
>> http://www.w3.org/TR/html401/ doesn't mention any "min" and "max"
>> attributes for the input element, and this doesn't seem to let you
>> select multiple files in IE7 or FF3.5. In which browser does this work?
>
>It seems that Opera has been an early bird implementing the
>then-proposed min/max behaviour for file inputs as in was
>mentioned in the webforms 2.0 draft
>(http://www.w3.org/TR/web-forms-2/).
>
>Yet this has never made it into an official recommendation, and while
>the current HTML5 draft does mention a "multiple" attribute for file
>inputs, it specifically disallows "min" and "max"
>(http://preview.tinyurl.com/mgpm7h).
>
Correct URL: <http://tinyurl.com/d7wtbu>.

Yes, it mandates the attribute 'multiple,' which is the language Safari
understand (and Opera doesn't seem to).

-- 
Ed Jay (remove 'M' to reply by email)

Win the War Against Breast Cancer.
Knowing the facts could save your life. 
http://www.breastthermography.info


------------------------------

Date: Fri, 07 Aug 2009 12:34:19 -0700
From: Ed Jay <edMbj@aes-intl.com>
Subject: Re: Process to upload multiple files from a single <input type=file>
Message-Id: <v60p75p0cccrn65hgjcmmd7jo3jifrjlti@4ax.com>

Steve C wrote:

>Ed Jay wrote:
>> I have a form that allows multiple files to be selected using a single
>> input element, e.g., <input type='file' min='1' max='999'>, and a Perl CGI
>> script to upload the files to my server. Unlike multiple single-file
>> uploads, the file that uploads is a concatenation of the individual files.
>> 
>> My questions is: How do I process the form information passed to the Perl
>> script such that I can recover the individual files and their respective
>> filenames?
>> 
>
>The docs claim that you will get upload data as a multipart mime type,
>just like email attachments, where the data for each file is separated
>by a mime header which includes the file path.
>
>If that's what you are getting, then the MIME::Parser module might be a
>good place to start.

Good place to start, but not a good place to solve my issue. It works to
parse files, particularly multi-part email, that are downloaded to the
client.

I need to access the multi-part file before it's uploaded. I have conjured
a method to separate the file into its constituents, but I have no idea
how to access the file before uploading.

Any help, further clues, or scripts are welcome.
 

-- 
Ed Jay (remove 'M' to reply by email)

Win the War Against Breast Cancer.
Knowing the facts could save your life. 
http://www.breastthermography.info


------------------------------

Date: Fri, 07 Aug 2009 16:44:54 -0400
From: Steve C <smallpond@juno.com>
Subject: Re: Process to upload multiple files from a single <input type=file>
Message-Id: <h5i47k$qp$1@news.eternal-september.org>

Ed Jay wrote:
> Steve C wrote:
> 
>> Ed Jay wrote:
>>> I have a form that allows multiple files to be selected using a single
>>> input element, e.g., <input type='file' min='1' max='999'>, and a Perl CGI
>>> script to upload the files to my server. Unlike multiple single-file
>>> uploads, the file that uploads is a concatenation of the individual files.
>>>
>>> My questions is: How do I process the form information passed to the Perl
>>> script such that I can recover the individual files and their respective
>>> filenames?
>>>
>> The docs claim that you will get upload data as a multipart mime type,
>> just like email attachments, where the data for each file is separated
>> by a mime header which includes the file path.
>>
>> If that's what you are getting, then the MIME::Parser module might be a
>> good place to start.
> 
> Good place to start, but not a good place to solve my issue. It works to
> parse files, particularly multi-part email, that are downloaded to the
> client.
> 
> I need to access the multi-part file before it's uploaded. I have conjured
> a method to separate the file into its constituents, but I have no idea
> how to access the file before uploading.
> 
> Any help, further clues, or scripts are welcome.
>  
> 

A CGI runs on the web server in response to a form submit.  What perl code
would be running on the local machine or before the submit?


------------------------------

Date: Fri, 07 Aug 2009 13:55:30 -0700
From: Ed Jay <edMbj@aes-intl.com>
Subject: Re: Process to upload multiple files from a single <input type=file>
Message-Id: <mv4p75tpr8fspd6r8t5h7qo19n7ssb992n@4ax.com>

Steve C wrote:

>Ed Jay wrote:
>> Steve C wrote:
>> 
>>> Ed Jay wrote:
>>>> I have a form that allows multiple files to be selected using a single
>>>> input element, e.g., <input type='file' min='1' max='999'>, and a Perl CGI
>>>> script to upload the files to my server. Unlike multiple single-file
>>>> uploads, the file that uploads is a concatenation of the individual files.
>>>>
>>>> My questions is: How do I process the form information passed to the Perl
>>>> script such that I can recover the individual files and their respective
>>>> filenames?
>>>>
>>> The docs claim that you will get upload data as a multipart mime type,
>>> just like email attachments, where the data for each file is separated
>>> by a mime header which includes the file path.
>>>
>>> If that's what you are getting, then the MIME::Parser module might be a
>>> good place to start.
>> 
>> Good place to start, but not a good place to solve my issue. It works to
>> parse files, particularly multi-part email, that are downloaded to the
>> client.
>> 
>> I need to access the multi-part file before it's uploaded. I have conjured
>> a method to separate the file into its constituents, but I have no idea
>> how to access the file before uploading.
>> 
>> Any help, further clues, or scripts are welcome.
>>  
>A CGI runs on the web server in response to a form submit.  What perl code
>would be running on the local machine or before the submit?

Thanks. I no sooner posted when I realized what I thought I was seeking is
impossible to accomplish using a server-side Perl script. I came back to
the NG to post it, but you beat me to it. 

-- 
Ed Jay (remove 'M' to reply by email)

Win the War Against Breast Cancer.
Knowing the facts could save your life. 
http://www.breastthermography.info


------------------------------

Date: Fri, 7 Aug 2009 21:49:22 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Process to upload multiple files from a single <input type=file>
Message-Id: <ijguk6-rfk2.ln1@osiris.mauzo.dyndns.org>


Quoth Ed Jay <edMbj@aes-intl.com>:
> Steve C wrote:
> 
> >Ed Jay wrote:
> >> I have a form that allows multiple files to be selected using a single
> >> input element, e.g., <input type='file' min='1' max='999'>, and a Perl CGI
> >> script to upload the files to my server. Unlike multiple single-file
> >> uploads, the file that uploads is a concatenation of the individual files.
> >> 
> >> My questions is: How do I process the form information passed to the Perl
> >> script such that I can recover the individual files and their respective
> >> filenames?
> >> 
> >
> >The docs claim that you will get upload data as a multipart mime type,
> >just like email attachments, where the data for each file is separated
> >by a mime header which includes the file path.
> >
> >If that's what you are getting, then the MIME::Parser module might be a
> >good place to start.
> 
> Good place to start, but not a good place to solve my issue. It works to
> parse files, particularly multi-part email, that are downloaded to the
> client.
> 
> I need to access the multi-part file before it's uploaded. I have conjured
> a method to separate the file into its constituents, but I have no idea
> how to access the file before uploading.

Since most of us don't use Opera, can you post exactly what you get as
the value of the file-upload field if you select, say, a file called
'a.txt' containing the string 'A' and a file called 'b.txt' containing
the string 'B'? Assuming this feature of Opera is anywhere near sane,
it's likely to be some sort of multipart MIME document, which you *can*
separate out with MIME::Parser (or some other MIME module).

Ben



------------------------------

Date: Fri, 07 Aug 2009 17:04:41 -0400
From: Steve C <smallpond@juno.com>
Subject: Re: Process to upload multiple files from a single <input type=file>
Message-Id: <h5i5cn$9rq$1@news.eternal-september.org>

Ed Jay wrote:
> Steve C wrote:
> 
>> Ed Jay wrote:
>>> Steve C wrote:
>>>
>>>> Ed Jay wrote:
>>>>> I have a form that allows multiple files to be selected using a single
>>>>> input element, e.g., <input type='file' min='1' max='999'>, and a Perl CGI
>>>>> script to upload the files to my server. Unlike multiple single-file
>>>>> uploads, the file that uploads is a concatenation of the individual files.
>>>>>
>>>>> My questions is: How do I process the form information passed to the Perl
>>>>> script such that I can recover the individual files and their respective
>>>>> filenames?
>>>>>
>>>> The docs claim that you will get upload data as a multipart mime type,
>>>> just like email attachments, where the data for each file is separated
>>>> by a mime header which includes the file path.
>>>>
>>>> If that's what you are getting, then the MIME::Parser module might be a
>>>> good place to start.
>>> Good place to start, but not a good place to solve my issue. It works to
>>> parse files, particularly multi-part email, that are downloaded to the
>>> client.
>>>
>>> I need to access the multi-part file before it's uploaded. I have conjured
>>> a method to separate the file into its constituents, but I have no idea
>>> how to access the file before uploading.
>>>
>>> Any help, further clues, or scripts are welcome.
>>>  
>> A CGI runs on the web server in response to a form submit.  What perl code
>> would be running on the local machine or before the submit?
> 
> Thanks. I no sooner posted when I realized what I thought I was seeking is
> impossible to accomplish using a server-side Perl script. I came back to
> the NG to post it, but you beat me to it. 
> 

You might be able to do something in Javascript to modify the submit but
you would probably be battling security issues.  Parsing the mime data
on the server shouldn't be that difficult.  Just don't pretend to run
into a pane of glass.




------------------------------

Date: Fri, 07 Aug 2009 14:25:16 -0700
From: Ed Jay <edMbj@aes-intl.com>
Subject: Re: Process to upload multiple files from a single <input type=file>
Message-Id: <0c6p7515si44fr0q5p4crjs9uqlq8l1uov@4ax.com>

Ben Morrow wrote:

>
>Quoth Ed Jay <edMbj@aes-intl.com>:
>> Steve C wrote:
>> 
>> >Ed Jay wrote:
>> >> I have a form that allows multiple files to be selected using a single
>> >> input element, e.g., <input type='file' min='1' max='999'>, and a Perl CGI
>> >> script to upload the files to my server. Unlike multiple single-file
>> >> uploads, the file that uploads is a concatenation of the individual files.
>> >> 
>> >> My questions is: How do I process the form information passed to the Perl
>> >> script such that I can recover the individual files and their respective
>> >> filenames?
>> >> 
>> >
>> >The docs claim that you will get upload data as a multipart mime type,
>> >just like email attachments, where the data for each file is separated
>> >by a mime header which includes the file path.
>> >
>> >If that's what you are getting, then the MIME::Parser module might be a
>> >good place to start.
>> 
>> Good place to start, but not a good place to solve my issue. It works to
>> parse files, particularly multi-part email, that are downloaded to the
>> client.
>> 
>> I need to access the multi-part file before it's uploaded. I have conjured
>> a method to separate the file into its constituents, but I have no idea
>> how to access the file before uploading.
>
>Since most of us don't use Opera, can you post exactly what you get as
>the value of the file-upload field if you select, say, a file called
>'a.txt' containing the string 'A' and a file called 'b.txt' containing
>the string 'B'? Assuming this feature of Opera is anywhere near sane,
>it's likely to be some sort of multipart MIME document, which you *can*
>separate out with MIME::Parser (or some other MIME module).
>
The raw filename is 'mixed' and the field value shows as
'multipart/mixed.'

Yes, I could use MIME::Parser, but only after the file is on the server. I
need the constituent files, named by me, but based on their original
filenames, to reside on the server. It seems to me that the process would
require an upload of the multipart file, separating it into its
constituent files using MIME::Parser, renaming and saving the individual
files, and then deleting the multipart file. While that seems to be a
solution, it seems inelegant, requires confirmation of the individual file
integrity, and is generally cumbersome. 

-- 
Ed Jay (remove 'M' to reply by email)

Win the War Against Breast Cancer.
Knowing the facts could save your life. 
http://www.breastthermography.info


------------------------------

Date: Fri, 07 Aug 2009 14:28:12 -0700
From: Ed Jay <edMbj@aes-intl.com>
Subject: Re: Process to upload multiple files from a single <input type=file>
Message-Id: <2u6p755uc2pvijtktvkl9t6s90ccva7jq0@4ax.com>

Steve C wrote:

>Ed Jay wrote:
>> Steve C wrote:
>> 
>>> Ed Jay wrote:
>>>> Steve C wrote:
>>>>
>>>>> Ed Jay wrote:
>>>>>> I have a form that allows multiple files to be selected using a single
>>>>>> input element, e.g., <input type='file' min='1' max='999'>, and a Perl CGI
>>>>>> script to upload the files to my server. Unlike multiple single-file
>>>>>> uploads, the file that uploads is a concatenation of the individual files.
>>>>>>
>>>>>> My questions is: How do I process the form information passed to the Perl
>>>>>> script such that I can recover the individual files and their respective
>>>>>> filenames?
>>>>>>
>>>>> The docs claim that you will get upload data as a multipart mime type,
>>>>> just like email attachments, where the data for each file is separated
>>>>> by a mime header which includes the file path.
>>>>>
>>>>> If that's what you are getting, then the MIME::Parser module might be a
>>>>> good place to start.
>>>> Good place to start, but not a good place to solve my issue. It works to
>>>> parse files, particularly multi-part email, that are downloaded to the
>>>> client.
>>>>
>>>> I need to access the multi-part file before it's uploaded. I have conjured
>>>> a method to separate the file into its constituents, but I have no idea
>>>> how to access the file before uploading.
>>>>
>>>> Any help, further clues, or scripts are welcome.
>>>>  
>>> A CGI runs on the web server in response to a form submit.  What perl code
>>> would be running on the local machine or before the submit?
>> 
>> Thanks. I no sooner posted when I realized what I thought I was seeking is
>> impossible to accomplish using a server-side Perl script. I came back to
>> the NG to post it, but you beat me to it. 
>> 
>You might be able to do something in Javascript to modify the submit but
>you would probably be battling security issues.  

Which is what led me to use Perl in the first place. Silly me!

>Parsing the mime data on the server shouldn't be that difficult. 

Agreed. It's the task totality attendant to doing it at the server that I
regret.

>Just don't pretend to run into a pane of glass.
>
Yes, that happens to me a lot. :-)

-- 
Ed Jay (remove 'M' to reply by email)

Win the War Against Breast Cancer.
Knowing the facts could save your life. 
http://www.breastthermography.info


------------------------------

Date: Fri, 7 Aug 2009 22:50:50 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Process to upload multiple files from a single <input type=file>
Message-Id: <q6kuk6-iuk2.ln1@osiris.mauzo.dyndns.org>


Quoth Ed Jay <edMbj@aes-intl.com>:
>
> The raw filename is 'mixed' and the field value shows as
> 'multipart/mixed.'

Then I suspect that CGI.pm (or whatever you are using) is getting
confused by the non-standard file-upload format. (Either that, or you're
misusing it; since you haven't posted any code yet it's impossible to
tell.)

If you are interested in actually solving this problem, then the first
thing to do is post a complete example of an HTTP request for a file
upload like this, and a cut-down version of the code you are trying to
use to process it.

> Yes, I could use MIME::Parser, but only after the file is on the server. I
> need the constituent files, named by me, but based on their original
> filenames, to reside on the server. It seems to me that the process would
> require an upload of the multipart file, separating it into its
> constituent files using MIME::Parser,

You don't have to save the POSTed data to a file before you process it.
If you get everything right, you can stream the incoming data through
MIME::Parser and directly into the appropriate files.

> renaming and saving the individual
> files, and then deleting the multipart file. While that seems to be a
> solution, it seems inelegant, requires confirmation of the individual file
> integrity, and is generally cumbersome. 

I don't know what you mean by 'requires confirmation of the individual
file integrity'. HTTP file upload never provides any guarantee of that,
beyond the TCP and (possibly) SSL checksums on the data stream. As for
having to split up the files, well, if you want to upload several files
as a single HTTP request, the client will have to join them together and
the server will have to split them up again. That's not 'inelegant',
it's common sense. Since you are using a non-standard feature of Opera,
it's possible that the usual libraries like CGI.pm don't handle the
upload properly; this may be annoying, but should be expected.

Ben



------------------------------

Date: Fri, 7 Aug 2009 11:23:03 -0700 (PDT)
From: pgodfrin <pgodfrin@gmail.com>
Subject: Re: using file globs and regex
Message-Id: <c9d92df2-0d9b-4d0b-be75-58a70291df7d@e34g2000vbm.googlegroups.com>

hmmm - what if I wanted to do some search on the glob?
like my($fn) =3D grep ( /5/ , glob 'f*');
?
pg
On Aug 7, 12:23=A0pm, pgodfrin <pgodf...@gmail.com> wrote:
> Thanks Tad - works like a charm...
> pg
>
> On Aug 7, 12:06=A0pm, Tad J McClellan <ta...@seesig.invalid> wrote:
>
> > pgodfrin <pgodf...@gmail.com> wrote:
> > > Greetings,
> > > This program works fine (with file names f1..f8 in the directory):
>
> > > #!/usr/bin/perl
> > > use warnings;
> > > use strict;
> > > $\=3D"\n";
> > > while(<f*>)
> > > {
> > > =A0 =A0 print "$_";
> > > =A0 =A0 if(/f5/)
> > > =A0 =A0 {
> > > =A0 =A0 =A0 =A0 my $fn=3D$_;
> > > =A0 =A0 =A0 =A0 print "File name $fn found..." and exit;
> > > =A0 =A0 }
> > > }
> > > exit;
>
> > > But I was hoping to be able to do something like:
> > > my $fn=3Dgrep (/f5/,<f*>);
>
> > > Basically just trying to have less lines of code...any suggestions?
>
> > use grep() in a list context instead of in a scalar context.
>
> > I don't like using overloaded angle brackets in my code.
>
> > If I want equality, I use an operator that tests for equality.
>
> > =A0 =A0 my($fn) =3D grep ( $_ eq 'f5' , glob 'f*');
>
> > --
> > Tad McClellan
> > email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
>
>



------------------------------

Date: Fri, 7 Aug 2009 12:21:52 -0700 (PDT)
From: pgodfrin <pgodfrin@gmail.com>
Subject: Re: using file globs and regex
Message-Id: <5a6603bb-1bc8-4f8b-98f3-6fe7d0bf7a27@n2g2000vba.googlegroups.com>

OK - I figured it out - thanks.

This works fine: my($fn2) =3D grep ( $_ =3D~ '6' , glob 'f*');

What I'm confused about is the parens around the $fn2 ? Why are those
needed? Something tells me that has something to do with making the
scalar $fn2 into a list 'cause that's what grep returns, but i can't
remember what that's called to look it up.

help?
pg


On Aug 7, 1:23=A0pm, pgodfrin <pgodf...@gmail.com> wrote:
> hmmm - what if I wanted to do some search on the glob?
> like my($fn) =3D grep ( /5/ , glob 'f*');
> ?
> pg
> On Aug 7, 12:23=A0pm, pgodfrin <pgodf...@gmail.com> wrote:
>
> > Thanks Tad - works like a charm...
> > pg
>
> > On Aug 7, 12:06=A0pm, Tad J McClellan <ta...@seesig.invalid> wrote:
>
> > > pgodfrin <pgodf...@gmail.com> wrote:
> > > > Greetings,
> > > > This program works fine (with file names f1..f8 in the directory):
>
> > > > #!/usr/bin/perl
> > > > use warnings;
> > > > use strict;
> > > > $\=3D"\n";
> > > > while(<f*>)
> > > > {
> > > > =A0 =A0 print "$_";
> > > > =A0 =A0 if(/f5/)
> > > > =A0 =A0 {
> > > > =A0 =A0 =A0 =A0 my $fn=3D$_;
> > > > =A0 =A0 =A0 =A0 print "File name $fn found..." and exit;
> > > > =A0 =A0 }
> > > > }
> > > > exit;
>
> > > > But I was hoping to be able to do something like:
> > > > my $fn=3Dgrep (/f5/,<f*>);
>
> > > > Basically just trying to have less lines of code...any suggestions?
>
> > > use grep() in a list context instead of in a scalar context.
>
> > > I don't like using overloaded angle brackets in my code.
>
> > > If I want equality, I use an operator that tests for equality.
>
> > > =A0 =A0 my($fn) =3D grep ( $_ eq 'f5' , glob 'f*');
>
> > > --
> > > Tad McClellan
> > > email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
>
>



------------------------------

Date: Fri, 7 Aug 2009 21:44:51 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: using file globs and regex
Message-Id: <3bguk6-rfk2.ln1@osiris.mauzo.dyndns.org>

[please don't top-post]

Quoth pgodfrin <pgodfrin@gmail.com>:
> OK - I figured it out - thanks.
> 
> This works fine: my($fn2) = grep ( $_ =~ '6' , glob 'f*');
> 
> What I'm confused about is the parens around the $fn2 ? Why are those
> needed? Something tells me that has something to do with making the
> scalar $fn2 into a list 'cause that's what grep returns, but i can't
> remember what that's called to look it up.

    my $x = ...

evaluates the RHS in scalar context, but

    my ($x) = ...

evaluates it in list context. The same applies without the 'my', or with
'local' instead. This is one of the few cases where explicit parens make
a difference in deciding whether something is a list or not.

Ben



------------------------------

Date: Fri, 07 Aug 2009 17:00:30 -0400
From: Steve C <smallpond@juno.com>
Subject: Re: using file globs and regex
Message-Id: <h5i54r$qp$2@news.eternal-september.org>

- SC.

then it asks grep for a scalar.
but when you call it without the parens
it asks grep for a list
When you put $fn2 inside the parens then
It's called list context.

pgodfrin wrote:
> OK - I figured it out - thanks.
> 
> This works fine: my($fn2) = grep ( $_ =~ '6' , glob 'f*');
> 
> What I'm confused about is the parens around the $fn2 ? Why are those
> needed? Something tells me that has something to do with making the
> scalar $fn2 into a list 'cause that's what grep returns, but i can't
> remember what that's called to look it up.
> 
> help?
> pg
> 
> 
> On Aug 7, 1:23 pm, pgodfrin <pgodf...@gmail.com> wrote:
>> hmmm - what if I wanted to do some search on the glob?
>> like my($fn) = grep ( /5/ , glob 'f*');
>> ?
>> pg
>> On Aug 7, 12:23 pm, pgodfrin <pgodf...@gmail.com> wrote:
>>
>>> Thanks Tad - works like a charm...
>>> pg
>>> On Aug 7, 12:06 pm, Tad J McClellan <ta...@seesig.invalid> wrote:
>>>> pgodfrin <pgodf...@gmail.com> wrote:
>>>>> Greetings,
>>>>> This program works fine (with file names f1..f8 in the directory):
>>>>> #!/usr/bin/perl
>>>>> use warnings;
>>>>> use strict;
>>>>> $\="\n";
>>>>> while(<f*>)
>>>>> {
>>>>>     print "$_";
>>>>>     if(/f5/)
>>>>>     {
>>>>>         my $fn=$_;
>>>>>         print "File name $fn found..." and exit;
>>>>>     }
>>>>> }
>>>>> exit;
>>>>> But I was hoping to be able to do something like:
>>>>> my $fn=grep (/f5/,<f*>);
>>>>> Basically just trying to have less lines of code...any suggestions?
>>>> use grep() in a list context instead of in a scalar context.
>>>> I don't like using overloaded angle brackets in my code.
>>>> If I want equality, I use an operator that tests for equality.
>>>>     my($fn) = grep ( $_ eq 'f5' , glob 'f*');
>>>> --
>>>> Tad McClellan
>>>> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
>>
> 


------------------------------

Date: Fri, 07 Aug 2009 16:05:15 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: using file globs and regex
Message-Id: <slrnh7p59u.355.tadmc@tadmc30.sbcglobal.net>


[ Please do not top-post, you have been posting here long enough to know this ]


pgodfrin <pgodfrin@gmail.com> wrote:

> This works fine: my($fn2) = grep ( $_ =~ '6' , glob 'f*');


If "fine" means put the first match into $fn2 and discard all
of the other matches, then it works.


> What I'm confused about is the parens around the $fn2 ? Why are those
> needed? 


To provide a list context, as I mentioned in my first followup.


> Something tells me that has something to do with making the
> scalar $fn2 into a list 'cause that's what grep returns, but i can't
> remember what that's called to look it up.


It is called "context". So you read about it in the "Context"
section of perldata.pod.

    interpretation of operations and values in Perl sometimes depends
    on the requirements of the context around the operation or value.
    ...
    Assignment is a little bit special in that it uses its left argument
    to determine the context for the right argument.  Assignment to a
    scalar evaluates the right-hand side in scalar context, while
    assignment to an array or hash evaluates the righthand side in list
    context.  Assignment to a list (or slice, which is just a list
    anyway) also evaluates the righthand side in list context.


[ snip upside-down quoted text ]


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


------------------------------

Date: Fri, 7 Aug 2009 22:26:38 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: using file globs and regex
Message-Id: <epiuk6-epk2.ln1@osiris.mauzo.dyndns.org>

[please don't top-post]

Quoth Steve C <smallpond@juno.com>:
> - SC.
> 
> then it asks grep for a scalar.
> but when you call it without the parens
> it asks grep for a list

Please don't talk nonsense.

Ben



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 2542
***************************************


home help back first fref pref prev next nref lref last post