[28337] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9701 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 8 00:05:52 2006

Date: Thu, 7 Sep 2006 21:05:05 -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           Thu, 7 Sep 2006     Volume: 10 Number: 9701

Today's topics:
        beginners question <nospam@diespammer.com>
    Re: beginners question <David.Squire@no.spam.from.here.au>
    Re: beginners question <David.Squire@no.spam.from.here.au>
    Re: beginners question <mgarrish@gmail.com>
    Re: beginners question <David.Squire@no.spam.from.here.au>
    Re: beginners question <mgarrish@gmail.com>
    Re: beginners question <john@castleamber.com>
    Re: beginners question <mumia.w.18.spam+nospam.usenet@earthlink.net>
    Re: beginners question <mumia.w.18.spam+nospam.usenet@earthlink.net>
    Re: beginners question <attn.steven.kuo@gmail.com>
    Re: beginners question <notvalid@email.com>
    Re: CPAN 'shell' interface stopped working? <dh1760@gmail.com>
        extract links from webpage yuetwah2000@hotmail.com
        extract links from webpage yuetwah2000@hotmail.com
    Re: extract links from webpage <mumia.w.18.spam+nospam.usenet@earthlink.net>
    Re: extract links from webpage <john@castleamber.com>
    Re: Non-uniform split <darkknight0072004@yahoo.com>
    Re: Numerical sort (Schwartzian xform) <awkster@yahoo.com>
    Re: Numerical sort (Schwartzian xform) <john@castleamber.com>
    Re: Pattern Matching and skipping <mattjones@hotmail.co.uk>
    Re: Pattern Matching and skipping <tadmc@augustmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 08 Sep 2006 11:25:48 +1000
From: Alpha <nospam@diespammer.com>
Subject: beginners question
Message-Id: <4500c69f$0$764$5a62ac22@per-qv1-newsreader-01.iinet.net.au>

Hi guys, n00bs here.

I was playing around with regexp and got stuck with this:
$string ="String 12345 String 67890 String whatever here";
basically i want to strip off the last "String" and whatever that comes 
after that.
so $string will become "String 12345 String 67890 ";

any hints will be appreciated.

Thanks,
Alpha


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

Date: Fri, 08 Sep 2006 02:31:48 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: beginners question
Message-Id: <edqh64$f4m$1@gemini.csx.cam.ac.uk>

Alpha wrote:
> Hi guys, n00bs here.
> 
> I was playing around with regexp and got stuck with this:
> $string ="String 12345 String 67890 String whatever here";
> basically i want to strip off the last "String" and whatever that comes 
> after that.
> so $string will become "String 12345 String 67890 ";
> 
> any hints will be appreciated.
> 
> Thanks,
> Alpha

my $String = 'String 12345 String 67890 String whatever here';
$string =~ s/^(String 12345 String 67890)/$1/;


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

Date: Fri, 08 Sep 2006 02:38:40 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: beginners question
Message-Id: <edqhj0$g9g$1@gemini.csx.cam.ac.uk>

David Squire wrote:
> Alpha wrote:
>> Hi guys, n00bs here.
>>
>> I was playing around with regexp and got stuck with this:
>> $string ="String 12345 String 67890 String whatever here";
>> basically i want to strip off the last "String" and whatever that 
>> comes after that.
>> so $string will become "String 12345 String 67890 ";
>>
>> any hints will be appreciated.
>>
>> Thanks,
>> Alpha
> 
> my $String = 'String 12345 String 67890 String whatever here';
> $string =~ s/^(String 12345 String 67890)/$1/;

D'oh

$String =~ s/^(String 12345 String 67890)/$1/;


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

Date: 7 Sep 2006 18:41:42 -0700
From: "Matt Garrish" <mgarrish@gmail.com>
Subject: Re: beginners question
Message-Id: <1157679702.934899.64110@d34g2000cwd.googlegroups.com>


David Squire wrote:

> Alpha wrote:
> > Hi guys, n00bs here.
> >
> > I was playing around with regexp and got stuck with this:
> > $string ="String 12345 String 67890 String whatever here";
> > basically i want to strip off the last "String" and whatever that comes
> > after that.
> > so $string will become "String 12345 String 67890 ";
> >
> > any hints will be appreciated.
> >
>

use strict;

> my $String = 'String 12345 String 67890 String whatever here';
> $string =~ s/^(String 12345 String 67890)/$1/;

You're just substituting the matched text back in place...

my $string = 'String 12345 String 67890 String whatever here';
$string =~ s/^((String \d+ *)+).*/$1/;

But you'd need to chomp the extra whitespace at the end.

Matt



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

Date: Fri, 08 Sep 2006 02:44:21 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: beginners question
Message-Id: <edqhtl$gs2$1@gemini.csx.cam.ac.uk>

Matt Garrish wrote:
> David Squire wrote:
> 
>> Alpha wrote:
>>> Hi guys, n00bs here.
>>>
>>> I was playing around with regexp and got stuck with this:
>>> $string ="String 12345 String 67890 String whatever here";
>>> basically i want to strip off the last "String" and whatever that comes
>>> after that.
>>> so $string will become "String 12345 String 67890 ";
>>>
>>> any hints will be appreciated.
>>>
> 
> use strict;
> 
>> my $String = 'String 12345 String 67890 String whatever here';
>> $string =~ s/^(String 12345 String 67890)/$1/;
> 
> You're just substituting the matched text back in place...
> 
> my $string = 'String 12345 String 67890 String whatever here';
> $string =~ s/^((String \d+ *)+).*/$1/;
> 
> But you'd need to chomp the extra whitespace at the end.

Yep. That's what I meant. Shouldn't post so late :(


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

Date: 7 Sep 2006 18:44:34 -0700
From: "Matt Garrish" <mgarrish@gmail.com>
Subject: Re: beginners question
Message-Id: <1157679874.312924.264030@m79g2000cwm.googlegroups.com>


Matt Garrish wrote:

> David Squire wrote:
>
> > Alpha wrote:
> > > Hi guys, n00bs here.
> > >
> > > I was playing around with regexp and got stuck with this:
> > > $string ="String 12345 String 67890 String whatever here";
> > > basically i want to strip off the last "String" and whatever that comes
> > > after that.
> > > so $string will become "String 12345 String 67890 ";
> > >
> > > any hints will be appreciated.
> > >
> >
>
> use strict;
>
> > my $String = 'String 12345 String 67890 String whatever here';
> > $string =~ s/^(String 12345 String 67890)/$1/;
>
> You're just substituting the matched text back in place...
>
> my $string = 'String 12345 String 67890 String whatever here';
> $string =~ s/^((String \d+ *)+).*/$1/;
   $string =~ s/^((String \d+ )+).*/$1/;

Doesn't really make a difference, but still a useless modiifer.

Matt



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

Date: 8 Sep 2006 01:47:03 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: beginners question
Message-Id: <Xns9837D36D2F738castleamber@130.133.1.4>

Alpha <nospam@diespammer.com> wrote:

> Hi guys, n00bs here.

Hi n00b, you can appear less n00bish by picking a good subject line. A lot 
of questions asked here are beginners questions, no need to pick that as a 
subject, it's often obvious :-D

> I was playing around with regexp and got stuck with this:
> $string ="String 12345 String 67890 String whatever here";
> basically i want to strip off the last "String" and whatever that comes 
> after that.
> so $string will become "String 12345 String 67890 ";
> 
> any hints will be appreciated.

Depending on your requirements, I assumed word number word number, the 
following might work:

$string =~ s/^(\w+ \d+ \w+ \d+ ).*/$1/;

-- 
John                Experienced Perl programmer: http://castleamber.com/

          Perl help, tutorials, and examples: http://johnbokma.com/perl/


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

Date: Fri, 08 Sep 2006 02:00:23 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: beginners question
Message-Id: <X84Mg.16489$Qf.4159@newsread2.news.pas.earthlink.net>

On 09/07/2006 08:25 PM, Alpha wrote:
> Hi guys, n00bs here.
> 
> I was playing around with regexp and got stuck with this:
> $string ="String 12345 String 67890 String whatever here";
> basically i want to strip off the last "String" and whatever that comes 
> after that.
> so $string will become "String 12345 String 67890 ";
> 
> any hints will be appreciated.
> 
> Thanks,
> Alpha

This is not a well-phrased question, and the subject line is 
not very descriptive, but here it goes:

$string =~ s/ what.*//;



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

Date: Fri, 08 Sep 2006 02:05:16 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: beginners question
Message-Id: <wd4Mg.4755$v%4.782@newsread1.news.pas.earthlink.net>

On 09/07/2006 09:00 PM, Mumia W. wrote:
> On 09/07/2006 08:25 PM, Alpha wrote:
>> Hi guys, n00bs here.
>>
>> I was playing around with regexp and got stuck with this:
>> $string ="String 12345 String 67890 String whatever here";
>> basically i want to strip off the last "String" and whatever that 
>> comes after that.
>> so $string will become "String 12345 String 67890 ";
>>
>> any hints will be appreciated.
>>
>> Thanks,
>> Alpha
> 
> This is not a well-phrased question, and the subject line is not very 
> descriptive, but here it goes:
> 
> $string =~ s/ what.*//;
> 

And that wasn't a well-phrased answer; this is:

$string =~ s/ *String what.*//;


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

Date: 7 Sep 2006 19:47:22 -0700
From: "attn.steven.kuo@gmail.com" <attn.steven.kuo@gmail.com>
Subject: Re: beginners question
Message-Id: <1157683642.482410.3370@e3g2000cwe.googlegroups.com>

Alpha wrote:
> Hi guys, n00bs here.
>
> I was playing around with regexp and got stuck with this:
> $string ="String 12345 String 67890 String whatever here";
> basically i want to strip off the last "String" and whatever that comes
> after that.
> so $string will become "String 12345 String 67890 ";
>
> any hints will be appreciated.
>


Try 'substr' instead:

substr($string, rindex($string, 'String')) = '';

print $string;

-- 
Hope this helps,
Steven



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

Date: Fri, 08 Sep 2006 03:36:36 GMT
From: Ala Qumsieh <notvalid@email.com>
Subject: Re: beginners question
Message-Id: <8z5Mg.16878$%j7.13275@newssvr29.news.prodigy.net>

Alpha wrote:
> Hi guys, n00bs here.
> 
> I was playing around with regexp and got stuck with this:
> $string ="String 12345 String 67890 String whatever here";
> basically i want to strip off the last "String" and whatever that comes 
> after that.
> so $string will become "String 12345 String 67890 ";

I don't think any of the given solutions is really what you're looking 
for. Perhaps this is?

	$string =~ s/(.*)String.*/$1/;

--Ala



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

Date: 7 Sep 2006 15:22:51 -0700
From: "Dave Hammond" <dh1760@gmail.com>
Subject: Re: CPAN 'shell' interface stopped working?
Message-Id: <1157667771.398020.188600@h48g2000cwc.googlegroups.com>

David Squire wrote:
> Dave Hammond wrote:

> > Maybe I should just
> >
> >   alias cpan='perl -MCPAN -e "shell"'
>
> ... why not try typing 'cpan'? It's almost certainly already there :)
>
>
> DS

True enough!  Man, think of all the keystrokes I've wasted over the
years!!

-Dave H.



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

Date: 7 Sep 2006 16:36:39 -0700
From: yuetwah2000@hotmail.com
Subject: extract links from webpage
Message-Id: <1157672199.468489.251060@p79g2000cwp.googlegroups.com>

how do I extract all links in a webpage? for example, I wanna extract
all .avi links in a webpage, can it be done with simple pattern
matching? What modules do I need?



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

Date: 7 Sep 2006 16:36:41 -0700
From: yuetwah2000@hotmail.com
Subject: extract links from webpage
Message-Id: <1157672201.927022.172870@m79g2000cwm.googlegroups.com>

how do I extract all links in a webpage? for example, I wanna extract
all .avi links in a webpage, can it be done with simple pattern
matching? What modules do I need?



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

Date: Fri, 08 Sep 2006 01:32:14 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: extract links from webpage
Message-Id: <yK3Mg.4744$v%4.2826@newsread1.news.pas.earthlink.net>

On 09/07/2006 06:36 PM, yuetwah2000@hotmail.com wrote:
> how do I extract all links in a webpage? for example, I wanna extract
> all .avi links in a webpage, can it be done with simple pattern
> matching? What modules do I need?
> 

cpan> m /HTML::Link/
 ...
Module          HTML::LinkExtor 
(G/GA/GAAS/HTML-Parser-3.55.tar.gz)
Module          HTML::LinkExtractor 
(P/PO/PODMASTER/HTML-LinkExtractor-0.13.tar.gz)
Module          HTML::LinkList 
(R/RU/RUBYKAT/HTML-LinkList-0.1001.tar.gz)
 ...




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

Date: 8 Sep 2006 01:40:23 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: extract links from webpage
Message-Id: <Xns9837D24B6E2BBcastleamber@130.133.1.4>

yuetwah2000@hotmail.com wrote:

> how do I extract all links in a webpage? for example, I wanna extract
> all .avi links in a webpage, can it be done with simple pattern
> matching? What modules do I need?

Download wget for all your pr0n needs :-)

wget -nd -r --accept avi http://example.com/

-- 
John                Experienced Perl programmer: http://castleamber.com/

          Perl help, tutorials, and examples: http://johnbokma.com/perl/


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

Date: 7 Sep 2006 15:48:19 -0700
From: "Dark" <darkknight0072004@yahoo.com>
Subject: Re: Non-uniform split
Message-Id: <1157669299.047845.313360@h48g2000cwc.googlegroups.com>

>
> Is there any other way apart from split by which i cud achieve this
> (assuming that there is no single regex to spit on) ?
>
> Any possible way (as far as I can loop..since no of lines is huge)
>
> Thanks.
> Greg

If you really want to use a regex here is something primative that
might get the job done (fills a hash and prints it - keeping track of
line numbers and columns). I'd probably just use unpack.

-I


$data = <<HERE
A      B       C          D      E
d32    ab      ae99       WB     89
d33    cd      e787       WC     78
d34    ef                 WD
d35    gh      ancjd      WT     100
d36    ij                 WP

HERE
;
@lines = split("\n", $data);
my %data;
my $counter;
for ($counter=0;$counter<=$#lines;$counter++) {
$line = $lines[$counter];
$_ = $line;
/([0-9\sa-zA-Z]{0,7})([0-9\sa-zA-Z]{0,8})([0-9\sa-zA-Z]{0,11})([0-9\sa-zA-Z]{0,7})([0-9\sa-zA-Z]{0,7})/;
if ($1) {
        $data{$counter}{'a'} = $1;
        $data{$counter}{'b'} = $2;
        $data{$counter}{'c'} = $3;
        $data{$counter}{'d'} = $4;
        $data{$counter}{'e'} = $5;
}
}

#Print out the data in the hash
for ($counter=0;$counter<=$#lines;$counter++) {
        my @cols;
     ($cols[0], $cols[1], $cols[2], $cols[3], $cols[4]) =
('a','b','c','d','e');
     for ($incount=0;$incount<=$#cols;$incount++) {
                print "Line $counter column
$cols[$incount]=\"$data{$counter}{$cols[$incount]}\"\n";
     }
     
}



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

Date: 7 Sep 2006 17:00:38 -0700
From: "Jorge" <awkster@yahoo.com>
Subject: Re: Numerical sort (Schwartzian xform)
Message-Id: <1157673638.570001.73140@i3g2000cwc.googlegroups.com>

The good advice was suggesting I reduce my program to something that is
managable for debugging -- which I did and it helped greatly.

Do I get paid by the line??? LOL -- actually I'm retired and Perl is a
necessity that supports my hobbies but I suppose if I programmed Perl
for a living, my Dr. Strangelove side would come out and I'd stop
worrying and learn how to love the one-liners. :)

Actually, your tips and style points are noted and appreciated and will
find themselves being used as I get used to the syntax.

have a good one ...

Jorge



Tad McClellan wrote:
> Jorge <awkster@yahoo.com> wrote:
>
> > Good advice
>
>
> What is good advice?
>
>
> > 	while(<IN>){
> > 		push(@array, $_);
> > 	}
>
>
> This does the same thing:
>
>    my @array = <IN>;
>
>
> > 	@sorted = sort @array;
>
>
> This does the same thing, only without the unnecessary temporary variable:
>
>    my @sorted = sort <IN>;
>
>
>
> > 	foreach $line(@sorted){
> > 		print "$line";
> > 	}
>
>
>    perldoc -q vars
>
>        What's wrong with always quoting "$vars"?
>
>
> This does the same thing:
>
>    print @sorted;
>
>
>
> Do you get paid by the line or something?
>
>
>
> [ snip TOFU. Please stop doing that! ]
>
> --
>     Tad McClellan                          SGML consulting
>     tadmc@augustmail.com                   Perl programming
>     Fort Worth, Texas



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

Date: 8 Sep 2006 01:38:33 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Numerical sort (Schwartzian xform)
Message-Id: <Xns9837D1FC5B593castleamber@130.133.1.4>

"Jorge" <awkster@yahoo.com> wrote:

> Actually, your tips and style points are noted and appreciated and
> will find themselves being used as I get used to the syntax.

Final tip, and "we" suggest to read it carefully:
<http://johnbokma.com/mexit/2006/04/11/how-to-reply.html>

-- 
John                Experienced Perl programmer: http://castleamber.com/

          Perl help, tutorials, and examples: http://johnbokma.com/perl/


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

Date: 7 Sep 2006 15:06:09 -0700
From: "MattJ83" <mattjones@hotmail.co.uk>
Subject: Re: Pattern Matching and skipping
Message-Id: <1157666769.052526.252750@i42g2000cwa.googlegroups.com>


David Squire wrote:
> MattJ83 wrote:
> > Ok guys,
> > Im not brushing your info to one side...but my plan was to get the code
> > running and then try and smarten it up....At the moment im just trying
> > to write something very basic that does the job.....which i almost
> > have.
> > I have a time constraint, so wanted to write some code to get the
> > information into the database and then i can start playing with the
> > code...
> >
> > If theres just no way of oing what I would like with this piece of code
> > inparticular then i obviously have to go back to  the drawing board and
> > look at it again......i just thought there should be some kind of way
> > to 'skip' over a /pattern/ to allow the script to keep running...
> >
>
> Sure there is:
>
> if (/pattern/) {
> 	# do whatever you want when there is a match
> }
> else {
> 	# do what is appropriate when there isn't a match, which could be as
> simple as "next;" to go on to the next loop iteration.
> }
>
> If you don't want to do anything when there is no match, you could just have
>
> next if !/pattern/;
>
> as the first line of your loop.
>
> You need to be willing to actually understand what you are doing though.
> This is a group for helping people with the Perl programming. Various
> people here have been trying to nudge you towards a solution to your
> problem, and towards better Perl programming practice in general.
>
> I learn something every day from participating here.
>
> On the other hand, perhaps you are looking for http://jobs.perl.org/
>
>
> DS
What you have mentioned here is what i've been trying to do all day but
with out any success - im actually a bit happier now because i can see
i am on the right lines - I was trying to do this yesterday but i think
because my knowledge is still quite limited I didn't have enough belief
that i was doing the right thing.........

I admit that i was getting completely confused with all the loops in
that code! I'll have another look tomorrow at these items and see if i
can put them in the right place with the correct syntax.....

I do appreciate your help in guiding me through this code - so far i've
just had a book and been told to right a script!



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

Date: Thu, 7 Sep 2006 18:40:31 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Pattern Matching and skipping
Message-Id: <slrneg1bff.f7d.tadmc@magna.augustmail.com>

MattJ83 <mattjones@hotmail.co.uk> wrote:

> I do appreciate your help in guiding me through this code - so far i've
> just had a book and been told to right a script!


Writing a script is not too difficult.

Righting a script is more difficult.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

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 V10 Issue 9701
***************************************


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