From joel at fentin.com Mon Aug 9 21:47:03 2010 From: joel at fentin.com (Joel Fentin) Date: Mon, 09 Aug 2010 21:47:03 -0700 Subject: [San-Diego-pm] Using a PHP script as a function Message-ID: <4C60D9C7.8040105@fentin.com> I have a perl program and I am trying to use a PHP script as a function. That is to say that my perl program passes data to it and it returns data. I have not been able to get it to run, let alone return data. If you take: http://calscape.com/dev/plant_editor/getPlantList.php?address=14295+recuerdo&city=del+mar&state=ca&zipcode=92014&native_status=native and put it in Firefox, it returns data which is displayed. First I tried 20 variations of: my $cmd = 'php ../dev/plant_editor/getPlantList.php?address=14295%20recuerdo&city=del%20mar&state=ca&zipcode=92014&native_status=native'; my $Stuff = `$cmd`; die "|$Stuff|"; It not only doesn't return data, but it doesn't seem to run the PHP. ====================== I also tried: my $xxx = system('http://calscape.com/dev/plant_editor/getPlantList.php?address=14295+recuerdo&city=del+mar&state=ca&zipcode=92014&native_status=native'); die "|$xxx|"; just to see if I could get it to run. I could not. ====================== I also tried: print "Content-type: text/html\n\n"; open(XXX,"http://calscape.com/dev/plant_editor/getPlantList.php?address=14295+recuerdo&city=del+mar&state=ca&zipcode=92014&native_status=native |"); while(){print} close(XXX); ====================== I've run out of ideas and nothing I Googled seemed to help. Suggestions please. -- Joel Fentin tel: 760-749-8863 Biz Website: http://fentin.com Personal Website: http://fentin.com/me From christopher.p.hart at gmail.com Mon Aug 9 21:53:21 2010 From: christopher.p.hart at gmail.com (Christopher Hart) Date: Mon, 9 Aug 2010 21:53:21 -0700 Subject: [San-Diego-pm] Using a PHP script as a function In-Reply-To: <4C60D9C7.8040105@fentin.com> References: <4C60D9C7.8040105@fentin.com> Message-ID: hi, make sure "../dev/plant_editor/getPlantList.php" has a php shebang #!/usr/bin/env php or whatever.. so it can run from CLI also, take out the url-encoded get parameters since perl wont be calling it in a browser. You may actually need to grab those vars from $argv or w/e the PHP mechanism for cmd line args is.. as opposed to $_POST or $_GET. :) Good Luck! On Mon, Aug 9, 2010 at 9:47 PM, Joel Fentin wrote: > I have a perl program and I am trying to use a PHP script as a function. > That is to say that my perl program passes data to it and it returns data. I > have not been able to get it to run, let alone return data. > > If you take: > > http://calscape.com/dev/plant_editor/getPlantList.php?address=14295+recuerdo&city=del+mar&state=ca&zipcode=92014&native_status=native > and put it in Firefox, it returns data which is displayed. > > First I tried 20 variations of: > my $cmd = 'php > ../dev/plant_editor/getPlantList.php?address=14295%20recuerdo&city=del%20mar&state=ca&zipcode=92014&native_status=native'; > my $Stuff = `$cmd`; > die "|$Stuff|"; > > It not only doesn't return data, but it doesn't seem to run the PHP. > > ====================== > > I also tried: > my $xxx = system(' > http://calscape.com/dev/plant_editor/getPlantList.php?address=14295+recuerdo&city=del+mar&state=ca&zipcode=92014&native_status=native' > ); > die "|$xxx|"; > > just to see if I could get it to run. I could not. > > ====================== > > I also tried: > print "Content-type: text/html\n\n"; > open(XXX," > http://calscape.com/dev/plant_editor/getPlantList.php?address=14295+recuerdo&city=del+mar&state=ca&zipcode=92014&native_status=native|"); > while(){print} > close(XXX); > > ====================== > > I've run out of ideas and nothing I Googled seemed to help. > Suggestions please. > > > > -- > Joel Fentin tel: 760-749-8863 > Biz Website: http://fentin.com > Personal Website: http://fentin.com/me > _______________________________________________ > San-Diego-pm mailing list > San-Diego-pm at pm.org > http://mail.pm.org/mailman/listinfo/san-diego-pm > -- Respectfully, Chris Hart Developer / System Administrator Insuremonkey.com 2080 E. Flamingo, Suite 223 Las Vegas, NV 89119 -------------- next part -------------- An HTML attachment was scrubbed... URL: From saaib at ciberlinux.net Mon Aug 9 22:03:08 2010 From: saaib at ciberlinux.net (Urivan Flores) Date: Mon, 9 Aug 2010 21:03:08 -0800 Subject: [San-Diego-pm] Using a PHP script as a function In-Reply-To: <4C60D9C7.8040105@fentin.com> References: <4C60D9C7.8040105@fentin.com> Message-ID: <20100810045922.M63882@ciberlinux.net> On Mon, 09 Aug 2010 21:47:03 -0700, Joel Fentin wrote > I have a perl program and I am trying to use a PHP script as a > function. That is to say that my perl program passes data to it > and it returns data. I have not been able to get it to run, let > alone return data. > > If you take: > http://calscape.com/dev/plant_editor/getPlantList.php?address=14295+recuerdo&city=del+mar&state=ca&zipcode=92014&native_status=native > and put it in Firefox, it returns data which is displayed. Joe, 1. You can use wget/curl to load the url: wget 'http://blablabla' (don't forget the single quotes around the URL) 2. Use LWP: #!/usr/bin/perl use LWP::Simple; my $data = get('http://blablabla/yourscript.php?yadda') or die 'Unable to get page'; Regards, -- Urivan Flores-Saaib saaib at ciberlinux.net (858) 431-9734 From christopher.p.hart at gmail.com Mon Aug 9 22:04:32 2010 From: christopher.p.hart at gmail.com (Christopher Hart) Date: Mon, 9 Aug 2010 22:04:32 -0700 Subject: [San-Diego-pm] Using a PHP script as a function In-Reply-To: <20100810045922.M63882@ciberlinux.net> References: <4C60D9C7.8040105@fentin.com> <20100810045922.M63882@ciberlinux.net> Message-ID: yea Urivan's is better.. that way you don't have to alter your php script :) On Mon, Aug 9, 2010 at 10:03 PM, Urivan Flores wrote: > On Mon, 09 Aug 2010 21:47:03 -0700, Joel Fentin wrote > > I have a perl program and I am trying to use a PHP script as a > > function. That is to say that my perl program passes data to it > > and it returns data. I have not been able to get it to run, let > > alone return data. > > > > If you take: > > > > http://calscape.com/dev/plant_editor/getPlantList.php?address=14295+recuerdo&city=del+mar&state=ca&zipcode=92014&native_status=native > > and put it in Firefox, it returns data which is displayed. > > Joe, > > 1. You can use wget/curl to load the url: > wget 'http://blablabla' > > (don't forget the single quotes around the URL) > > 2. Use LWP: > > #!/usr/bin/perl > use LWP::Simple; > > my $data = get('http://blablabla/yourscript.php?yadda') or > die 'Unable to get page'; > > Regards, > > -- > Urivan Flores-Saaib > saaib at ciberlinux.net > (858) 431-9734 > > _______________________________________________ > San-Diego-pm mailing list > San-Diego-pm at pm.org > http://mail.pm.org/mailman/listinfo/san-diego-pm > -- Respectfully, Chris Hart Developer / System Administrator Insuremonkey.com 2080 E. Flamingo, Suite 223 Las Vegas, NV 89119 -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel at fentin.com Tue Aug 10 14:02:08 2010 From: joel at fentin.com (Joel Fentin) Date: Tue, 10 Aug 2010 14:02:08 -0700 Subject: [San-Diego-pm] Using a PHP script as a function In-Reply-To: <20100810045922.M63882@ciberlinux.net> References: <4C60D9C7.8040105@fentin.com> <20100810045922.M63882@ciberlinux.net> Message-ID: <4C61BE50.5060003@fentin.com> Urivan, LWP::Simple did the trick. Thank you so much. Urivan Flores wrote: > On Mon, 09 Aug 2010 21:47:03 -0700, Joel Fentin wrote >> I have a perl program and I am trying to use a PHP script as a >> function. That is to say that my perl program passes data to it >> and it returns data. I have not been able to get it to run, let >> alone return data. >> >> If you take: >> > http://calscape.com/dev/plant_editor/getPlantList.php?address=14295+recuerdo&city=del+mar&state=ca&zipcode=92014&native_status=native >> and put it in Firefox, it returns data which is displayed. > > Joe, > > 1. You can use wget/curl to load the url: > wget 'http://blablabla' > > (don't forget the single quotes around the URL) > > 2. Use LWP: > > #!/usr/bin/perl > use LWP::Simple; > > my $data = get('http://blablabla/yourscript.php?yadda') or > die 'Unable to get page'; > > Regards, > > -- > Urivan Flores-Saaib > saaib at ciberlinux.net > (858) 431-9734 > > > -- Joel Fentin tel: 760-749-8863 Biz Website: http://fentin.com Personal Website: http://fentin.com/me From rkleeman at energoncube.net Tue Aug 17 09:59:45 2010 From: rkleeman at energoncube.net (Bob Kleemann) Date: Tue, 17 Aug 2010 09:59:45 -0700 Subject: [San-Diego-pm] Meeting this week! Message-ID: Hello SD Perl Mongers, Our normal monthly meeting is this week, Thursday, August 19th. We'll be meeting at the same location, the offices of Anonymizer.com, near I-805 and Mira Mesa Blvd. This month, in addition to our normal conversation and banter, we hope to talk about the Open Source Convention, plus anything else you want to talk about. If you plan to come, please let me know so we can save you a seat. I look forward to seeing everybody on Thursday! From rkleeman at energoncube.net Thu Aug 19 12:16:57 2010 From: rkleeman at energoncube.net (Bob Kleemann) Date: Thu, 19 Aug 2010 12:16:57 -0700 Subject: [San-Diego-pm] Meeting tonight! Message-ID: Perl Mongers, We have our normal monthly meeting tonight. It should be a good meeting, with people talking about the Open Source Convention that was in Portland late last month. In addition, we'll talk about the normal things, Perl, questions, and probably a couple of other things. Come and enjoy the fun. I look forward to seeing you all tonight! -- Bob, the Camel Wrangler. From joel at fentin.com Sun Aug 22 13:57:03 2010 From: joel at fentin.com (Joel Fentin) Date: Sun, 22 Aug 2010 13:57:03 -0700 Subject: [San-Diego-pm] Photo download problem Message-ID: <4C718F1F.7060508@fentin.com> THE FILE http://fentin.com/cgi-bin/temp.pl ============================ THE PERL CODE #!/usr/bin/perl -w use strict;use DBI;use CGI qw/:standard/; BEGIN{use CGI::Carp qw(carpout fatalsToBrowser);carpout(\*STDOUT);$|=1;} #Don't buffer err msg use LWP::Simple; my ($Content2,$f); print "Content-type: text/html\n\n"; $f = 'http://commons.wikimedia.org/wiki/File:PacificSilverFir_7645.jpg'; $Content2 = get($f); print length($Content2)."
"; $f = 'http://upload.wikimedia.org/wikipedia/commons/1/19/PacificSilverFir_7645.jpg'; $Content2 = get($f); print length($Content2)."
"; $f = 'http://fentin.com/Ecuador/B_Tuncarta-Children.jpg'; $Content2 = get($f); print length($Content2)."
"; print "
DONE"; ============================ Wikimedia permits the downloading of photos and hotlinking. Yet I can't get it to do anything with perl. The two URLs above (same photo in each case) work in the FF browser. The third example is from my own website as test. It downloads content. I sure would appreciate any clue as to what is at work here. -- Joel Fentin tel: 760-749-8863 Biz Website: http://fentin.com Personal Website: http://fentin.com/me From chris at chrisgrau.com Sun Aug 22 14:24:49 2010 From: chris at chrisgrau.com (Chris Grau) Date: Sun, 22 Aug 2010 14:24:49 -0700 Subject: [San-Diego-pm] Photo download problem In-Reply-To: <4C718F1F.7060508@fentin.com> References: <4C718F1F.7060508@fentin.com> Message-ID: <20100822212449.GA2565@chrisgrau.com> > http://fentin.com/cgi-bin/temp.pl [snip] > Wikimedia permits the downloading of photos and hotlinking. Yet I > can't get it to do anything with perl. The two URLs above (same photo > in each case) work in the FF browser. The third example is from my own > website as test. It downloads content. I seem to have the opposite results when running your test code. I receive an error attempting to download wikimedia's content (trimmed): $ HEAD http://upload.wikimedia.org/wikipedia/commons/1/19/PacificSilverFir_7645.jpg 403 Forbidden X-Squid-Error: ERR_ACCESS_DENIED 0 They must be blocking LWP's user agent, because wget works fine. I didn't bother testing a modified user agent string in LWP. > $f = 'http://commons.wikimedia.org/wiki/File:PacificSilverFir_7645.jpg'; > $Content2 = get($f); > print length($Content2)."
"; > > $f = 'http://upload.wikimedia.org/wikipedia/commons/1/19/PacificSilverFir_7645.jpg'; > $Content2 = get($f); > print length($Content2)."
"; > > $f = 'http://fentin.com/Ecuador/B_Tuncarta-Children.jpg'; > $Content2 = get($f); > print length($Content2)."
"; > print "
DONE"; What are you trying to accomplish? All three get() statements theoretically download the content of the URL. In fact, running your script, the file on your website was the only one to successfully download (again, the apparent user agent problem). From joel at fentin.com Sun Aug 22 16:37:25 2010 From: joel at fentin.com (Joel Fentin) Date: Sun, 22 Aug 2010 16:37:25 -0700 Subject: [San-Diego-pm] Photo download problem In-Reply-To: <20100822212449.GA2565@chrisgrau.com> References: <4C718F1F.7060508@fentin.com> <20100822212449.GA2565@chrisgrau.com> Message-ID: <4C71B4B5.1010406@fentin.com> Chris Grau wrote: >> http://fentin.com/cgi-bin/temp.pl > [snip] > >> Wikimedia permits the downloading of photos and hotlinking. Yet I >> can't get it to do anything with perl. The two URLs above (same photo >> in each case) work in the FF browser. The third example is from my own >> website as test. It downloads content. > > I seem to have the opposite results when running your test code. I > receive an error attempting to download wikimedia's content (trimmed): > > $ HEAD http://upload.wikimedia.org/wikipedia/commons/1/19/PacificSilverFir_7645.jpg > 403 Forbidden > X-Squid-Error: ERR_ACCESS_DENIED 0 > > They must be blocking LWP's user agent, because wget works fine. I > didn't bother testing a modified user agent string in LWP. Are you saying that it works fine in the browser because the browser has a different user agent? And if so, are you saying that I have to spoof a user agent to get the photos? >> $f = 'http://commons.wikimedia.org/wiki/File:PacificSilverFir_7645.jpg'; >> $Content2 = get($f); >> print length($Content2)."
"; >> >> $f = 'http://upload.wikimedia.org/wikipedia/commons/1/19/PacificSilverFir_7645.jpg'; >> $Content2 = get($f); >> print length($Content2)."
"; >> >> $f = 'http://fentin.com/Ecuador/B_Tuncarta-Children.jpg'; >> $Content2 = get($f); >> print length($Content2)."
"; >> print "
DONE"; > > What are you trying to accomplish? My client wants to download thousands of plant pictures. He is being very careful about photo credits and copyright issues. I currently have a list of about 20,000 photos he wants. Wikimedia is one of the sources. I wrote a Perl program to loop through the list. It failed at the first photo. I've been try a variety of ways to get that first photo. All three get() statements > theoretically download the content of the URL. In fact, running your > script, the file on your website was the only one to successfully > download (again, the apparent user agent problem). The fact that you have identified this as a user agent problem is helpful. I'm not sure what to do with it yet, but it's much better than nothing. -- Joel Fentin tel: 760-749-8863 Biz Website: http://fentin.com Personal Website: http://fentin.com/me From wrinkles at gmail.com Sun Aug 22 16:45:21 2010 From: wrinkles at gmail.com (Rick) Date: Sun, 22 Aug 2010 16:45:21 -0700 Subject: [San-Diego-pm] Photo download problem In-Reply-To: <4C71B4B5.1010406@fentin.com> References: <4C718F1F.7060508@fentin.com> <20100822212449.GA2565@chrisgrau.com> <4C71B4B5.1010406@fentin.com> Message-ID: Might WWW-Mechanize help? Rick Bychowski http://hiranyaloka.com On Sun, Aug 22, 2010 at 4:37 PM, Joel Fentin wrote: > The fact that you have identified this as a user agent problem is helpful. > I'm not sure what to do with it yet, but it's much better than nothing. > > > -- > -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at chrisgrau.com Mon Aug 23 07:14:27 2010 From: chris at chrisgrau.com (Chris Grau) Date: Mon, 23 Aug 2010 07:14:27 -0700 Subject: [San-Diego-pm] Photo download problem In-Reply-To: <4C71B4B5.1010406@fentin.com> References: <4C718F1F.7060508@fentin.com> <20100822212449.GA2565@chrisgrau.com> <4C71B4B5.1010406@fentin.com> Message-ID: <20100823141427.GA14521@chrisgrau.com> On Sun, Aug 22, 2010 at 04:37:25PM -0700, Joel Fentin wrote: > Chris Grau wrote: >>> http://fentin.com/cgi-bin/temp.pl >> [snip] >> >>> Wikimedia permits the downloading of photos and hotlinking. Yet I >>> can't get it to do anything with perl. The two URLs above (same photo >>> in each case) work in the FF browser. The third example is from my own >>> website as test. It downloads content. >> >> I seem to have the opposite results when running your test code. I >> receive an error attempting to download wikimedia's content (trimmed): >> >> $ HEAD http://upload.wikimedia.org/wikipedia/commons/1/19/PacificSilverFir_7645.jpg >> 403 Forbidden >> X-Squid-Error: ERR_ACCESS_DENIED 0 >> >> They must be blocking LWP's user agent, because wget works fine. I >> didn't bother testing a modified user agent string in LWP. > > Are you saying that it works fine in the browser because the browser > has a different user agent? Yes. > And if so, are you saying that I have to spoof a user agent to get the > photos? Again, yes. This, for example, works: use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->agent( 'Wget/1.10.2' ); my $response = $ua->get( 'http://upload.wikimedia.org/wikipedia/commons/1/19/PacificSilverFir_7645.jpg' ); if ( $response->is_success ) { say $response->status_line; say $response->content_type; } Resulting in: 200 OK image/jpeg From joel at fentin.com Tue Aug 24 12:51:32 2010 From: joel at fentin.com (Joel Fentin) Date: Tue, 24 Aug 2010 12:51:32 -0700 Subject: [San-Diego-pm] Photo download problem In-Reply-To: <20100823141427.GA14521@chrisgrau.com> References: <4C718F1F.7060508@fentin.com> <20100822212449.GA2565@chrisgrau.com> <4C71B4B5.1010406@fentin.com> <20100823141427.GA14521@chrisgrau.com> Message-ID: <4C7422C4.1080400@fentin.com> Chris Grau wrote: > > ...This, for example, works: > > use LWP::UserAgent; > > my $ua = LWP::UserAgent->new; > $ua->agent( 'Wget/1.10.2' ); > > my $response = $ua->get( > 'http://upload.wikimedia.org/wikipedia/commons/1/19/PacificSilverFir_7645.jpg' > ); > > if ( $response->is_success ) { > say $response->status_line; > say $response->content_type; > } > > Resulting in: > > 200 OK > image/jpeg Thank you Chris. That did the trick. And thank you Rick. I was on the verge of trying your golden suggestion when Chris's example code arrived. As you know a working example at hand is worth two in the bush. -- Joel Fentin tel: 760-749-8863 Biz Website: http://fentin.com Personal Website: http://fentin.com/me From joel at fentin.com Mon Aug 30 19:36:31 2010 From: joel at fentin.com (Joel Fentin) Date: Mon, 30 Aug 2010 19:36:31 -0700 Subject: [San-Diego-pm] Sort problem Message-ID: <4C7C6AAF.6040103@fentin.com> I've tried everything I can think of without success. my @A = ('aaa10.jpg','aaa9.jpg','bbb9.jpg','bbb10.jpg'); The desired order: aaa9.jpg aaa10.jpg bbb9.jpg bbb10.jpg Sorted first by the text. Those with the same text sorted numerically. Any help appreciated. perl perl perl -- Joel Fentin tel: 760-749-8863 Biz Website: http://fentin.com Personal Website: http://fentin.com/me From merlyn at stonehenge.com Mon Aug 30 19:39:23 2010 From: merlyn at stonehenge.com (Randal L. Schwartz) Date: Mon, 30 Aug 2010 19:39:23 -0700 Subject: [San-Diego-pm] Sort problem In-Reply-To: <4C7C6AAF.6040103@fentin.com> (Joel Fentin's message of "Mon, 30 Aug 2010 19:36:31 -0700") References: <4C7C6AAF.6040103@fentin.com> Message-ID: <8639tvcxpg.fsf@red.stonehenge.com> >>>>> "Joel" == Joel Fentin writes: Joel> I've tried everything I can think of without success. Joel> my @A = ('aaa10.jpg','aaa9.jpg','bbb9.jpg','bbb10.jpg'); Joel> The desired order: Joel> aaa9.jpg Joel> aaa10.jpg Joel> bbb9.jpg Joel> bbb10.jpg Joel> Sorted first by the text. Those with the same text sorted Joel> numerically. my @sorted = map $_->[0], sort { $a->[1] cmp $b->[1] or $a->[2] <=> $b->[2] } map [$_, /^(\D+)(\d+)/], @input; Untested, but I usually get this stuff mostly right. :) -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion From christopher.p.hart at gmail.com Mon Aug 30 20:53:00 2010 From: christopher.p.hart at gmail.com (Christopher Hart) Date: Mon, 30 Aug 2010 20:53:00 -0700 Subject: [San-Diego-pm] Sort problem In-Reply-To: <8639tvcxpg.fsf@red.stonehenge.com> References: <4C7C6AAF.6040103@fentin.com> <8639tvcxpg.fsf@red.stonehenge.com> Message-ID: "Untested, but I usually get this stuff mostly right. :)" I LOL'ed when I read this from the man who taught most of us perl. :) On Mon, Aug 30, 2010 at 7:39 PM, Randal L. Schwartz wrote: > >>>>> "Joel" == Joel Fentin writes: > > Joel> I've tried everything I can think of without success. > Joel> my @A = ('aaa10.jpg','aaa9.jpg','bbb9.jpg','bbb10.jpg'); > > Joel> The desired order: > Joel> aaa9.jpg > Joel> aaa10.jpg > Joel> bbb9.jpg > Joel> bbb10.jpg > > Joel> Sorted first by the text. Those with the same text sorted > Joel> numerically. > > my @sorted = > map $_->[0], > sort { $a->[1] cmp $b->[1] or $a->[2] <=> $b->[2] } > map [$_, /^(\D+)(\d+)/], > @input; > > Untested, but I usually get this stuff mostly right. :) > > -- > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 > > Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. > See http://methodsandmessages.vox.com/ for Smalltalk and Seaside > discussion > _______________________________________________ > San-Diego-pm mailing list > San-Diego-pm at pm.org > http://mail.pm.org/mailman/listinfo/san-diego-pm > -- Respectfully, Chris Hart Developer / System Administrator Insuremonkey.com 2080 E. Flamingo, Suite 223 Las Vegas, NV 89119 -------------- next part -------------- An HTML attachment was scrubbed... URL: From xrz1138 at gmail.com Mon Aug 30 21:05:31 2010 From: xrz1138 at gmail.com (Christopher Hahn) Date: Mon, 30 Aug 2010 21:05:31 -0700 Subject: [San-Diego-pm] Sort problem In-Reply-To: References: <4C7C6AAF.6040103@fentin.com> <8639tvcxpg.fsf@red.stonehenge.com> Message-ID: Yeah, I was like "I remember that one"......lol, it is only named after Merlyn. ;0) 2010/8/30 Christopher Hart > "Untested, but I usually get this stuff mostly right. :)" > > I LOL'ed when I read this from the man who taught most of us perl. > :) > > > On Mon, Aug 30, 2010 at 7:39 PM, Randal L. Schwartz > wrote: > >> >>>>> "Joel" == Joel Fentin writes: >> >> Joel> I've tried everything I can think of without success. >> Joel> my @A = ('aaa10.jpg','aaa9.jpg','bbb9.jpg','bbb10.jpg'); >> >> Joel> The desired order: >> Joel> aaa9.jpg >> Joel> aaa10.jpg >> Joel> bbb9.jpg >> Joel> bbb10.jpg >> >> Joel> Sorted first by the text. Those with the same text sorted >> Joel> numerically. >> >> my @sorted = >> map $_->[0], >> sort { $a->[1] cmp $b->[1] or $a->[2] <=> $b->[2] } >> map [$_, /^(\D+)(\d+)/], >> @input; >> >> Untested, but I usually get this stuff mostly right. :) >> >> -- >> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 >> 0095 >> >> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. >> See http://methodsandmessages.vox.com/ for Smalltalk and Seaside >> discussion >> _______________________________________________ >> San-Diego-pm mailing list >> San-Diego-pm at pm.org >> http://mail.pm.org/mailman/listinfo/san-diego-pm >> > > -- > Respectfully, > Chris Hart > Developer / System Administrator > Insuremonkey.com > 2080 E. Flamingo, Suite 223 > Las Vegas, NV 89119 > > _______________________________________________ > San-Diego-pm mailing list > San-Diego-pm at pm.org > http://mail.pm.org/mailman/listinfo/san-diego-pm > -- Realisant mon espoir, je me lance vers la gloire. Christopher Hahn == xrz1138 at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel at fentin.com Tue Aug 31 16:00:28 2010 From: joel at fentin.com (Joel Fentin) Date: Tue, 31 Aug 2010 16:00:28 -0700 Subject: [San-Diego-pm] Sort problem In-Reply-To: <8639tvcxpg.fsf@red.stonehenge.com> References: <4C7C6AAF.6040103@fentin.com> <8639tvcxpg.fsf@red.stonehenge.com> Message-ID: <4C7D898C.50107@fentin.com> That did the trick. Thank you On 8/30/2010 7:39 PM, Randal L. Schwartz wrote: >>>>>> "Joel" == Joel Fentin writes: > > Joel> I've tried everything I can think of without success. > Joel> my @A = ('aaa10.jpg','aaa9.jpg','bbb9.jpg','bbb10.jpg'); > > Joel> The desired order: > Joel> aaa9.jpg > Joel> aaa10.jpg > Joel> bbb9.jpg > Joel> bbb10.jpg > > Joel> Sorted first by the text. Those with the same text sorted > Joel> numerically. > > my @sorted = > map $_->[0], > sort { $a->[1] cmp $b->[1] or $a->[2]<=> $b->[2] } > map [$_, /^(\D+)(\d+)/], > @input; > > Untested, but I usually get this stuff mostly right. :) > -- Joel Fentin tel: 760-749-8863 Biz Website: http://fentin.com Personal Website: http://fentin.com/me