[19050] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1245 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 4 14:10:32 2001

Date: Wed, 4 Jul 2001 11:10:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <994270211-v10-i1245@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 4 Jul 2001     Volume: 10 Number: 1245

Today's topics:
    Re: regexp across lines <pne-news-20010704@newton.digitalspace.net>
    Re: regexp across lines (Tad McClellan)
    Re: regexp across lines <dommit@videotron.ca>
    Re: Retrieving Domain from URL line <tony_curtis32@yahoo.com>
        test <guillem@burns.upc.es>
        TESTERRRR <CPtester@yahoo.com>
        TESTERRRR <CPtester@yahoo.com>
    Re: two changes (Anno Siegel)
    Re: two changes <pne-news-20010704@newton.digitalspace.net>
    Re: two changes <rlogsdon@io.com>
    Re: Using functions inside regular expressions <joonas.paalasmaa@nokia.com>
    Re: Using functions inside regular expressions <peb@bms.umist.ac.uk>
    Re: Using functions inside regular expressions (Tad McClellan)
    Re: XS and perlcrt <randy@theoryx5.uwinnipeg.ca>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 04 Jul 2001 15:33:24 +0200
From: Philip Newton <pne-news-20010704@newton.digitalspace.net>
Subject: Re: regexp across lines
Message-Id: <7866kt01pdhe92485s3eim85sn7ttdeqju@4ax.com>

On Wed, 04 Jul 2001 08:54:43 -0400, Benjamin Goldberg
<goldbb2@earthlink.net> wrote:

> Dominic Mitchell wrote:
> > Thanks Philip for your advice.  My problem is now fixed.  I just
> > had to set $/="" and everything seems very smooth now!.
> 
> Actually, you should set $/ to undef, not "", since you want the whole
                ^^^^^^

> file, not just until the next blank line...

That depends on his data. If each bibliography entry (or whatever they
are) is a paragraph of its own, then "" is fine. If empty lines are
allowed in the middle of an entry, then he has a problem with "". But if
the format is controlled, then he can make things easier for himself.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Wed, 4 Jul 2001 09:22:34 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: regexp across lines
Message-Id: <slrn9k664q.d2f.tadmc@tadmc26.august.net>

Benjamin Goldberg <goldbb2@earthlink.net> wrote:

>Actually, you should set $/ to undef, 


Regardless of what you set $/ to, you should be sure to localize
the change to that global variable. Wrap the code that needs $/
set to something other than the default in a block to control
the effect of changing the global $/ variable's value:

   { local $/;   # slurp mode
     $_ = <>;    # slurp the entire file
   }

   # $/ now has its "expected" value again


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


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

Date: 04 Jul 2001 11:55:35 -0400
From: Dominic Mitchell <dommit@videotron.ca>
Subject: Re: regexp across lines
Message-Id: <m3bsn01yfc.fsf@rlevesque.com>



Philip Newton <pne-news-20010704@newton.digitalspace.net> writes:


> > > Thanks Philip for your advice.  My problem is now fixed.  I just
> > > had to set $/="" and everything seems very smooth now!.
> > 
> > Actually, you should set $/ to undef, not "", since you want the whole
>                 ^^^^^^
> 
> That depends on his data. If each bibliography entry (or whatever they
> are) is a paragraph of its own, then "" is fine. If empty lines are
> allowed in the middle of an entry, then he has a problem with "". But if
> the format is controlled, then he can make things easier for himself.
> 
 Which is exactly the case.  Each bibliography entry are separated
 by empty lines.

Thanks.

Dominic.




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

Date: 04 Jul 2001 09:38:18 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Retrieving Domain from URL line
Message-Id: <871ynwahet.fsf@limey.hpcc.uh.edu>

>> On 04 Jul 2001 03:33:49 GMT,
>> blstone77@aol.com (Blstone77) said:

> I have a perl program which creates a file with Referrer
> URL's one on each line like so.

> http://perlnewbies.com/history/searchit.html
> http://excite.com/search.gw?c=web&lk=excite_home_us&s
> http://search.msn.co.uk/spbasic.htm?MT=Presidents
> http://search.msn.com/results.asp?RS=CHECKED&Armada
> http://search.yahoo.com/bin/search?p=%22Perl
> http://top.cswap.com/cat/?biblestudies

> etc.. As you probably can guess, i would like to count
> up the times each domain sends someone to my page.  My
> question is how would I get Perl to extract just the
> domain names (excite.com, perlnewbies.com, msn.com,
> etc.) from this file.

not a regexp in sight...


use strict;
use URI;

my %count;

while (<DATA>) {
  chomp;
  my $uri = new URI $_;
  ++$count{lc $uri->host}; # Yahoo.COM and yahoo.com are the same
}

# descending order of occurrence
foreach my $host (sort {$count{$b} <=> $count{$a}} keys %count) {
  print "$host $count{$host}\n";
}

__DATA__
http://perlnewbies.com/history/searchit.html
http://excite.com/search.gw?c=web&lk=excite_home_us&s
http://search.yahoo.com/bin/search?p=Zummat
http://search.msn.co.uk/spbasic.htm?MT=Presidents
http://search.msn.com/results.asp?RS=CHECKED&Armada
http://search.yahoo.com/bin/search?p=%22Perl
http://top.cswap.com/cat/?biblestudies

<end code>

hth
t
-- 
Beep beep!  Out of my way, I'm a motorist!


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

Date: 04 Jul 2001 16:50:00 +0200
From: Guillem Colomer <guillem@burns.upc.es>
Subject: test
Message-Id: <7dlmm4oijr.fsf@burns.upc.es>

test


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

Date: Wed, 04 Jul 2001 12:04:36 -0400
From: CPTester <CPtester@yahoo.com>
Subject: TESTERRRR
Message-Id: <3B433E94.894D8088@yahoo.com>





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

Date: Wed, 04 Jul 2001 12:06:22 -0400
From: CPTester <CPtester@yahoo.com>
Subject: TESTERRRR
Message-Id: <3B433EFE.BFCA621C@yahoo.com>





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

Date: 4 Jul 2001 15:41:54 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: two changes
Message-Id: <9hvdg2$s18$1@mamenchi.zrz.TU-Berlin.DE>

According to Philip Newton  <nospam.newton@gmx.li>:
> On Wed, 4 Jul 2001 02:52:56 -0500, Michael Gilfix <magilfix@us.ibm.com>
> wrote:
> 
> > Try something like:
> > 
> > #!/bin/sh -- # Last bit is to stop perl looping
> > eval 'exec `which perl` -S $0 ${1+"$@"}'
> >   if 0;
> 
> Or    #!/usr/bin/env perl     , if you know that Perl is going to be on
> the default search path (well, it has to be for `which perl` to work, as
> well). I believe that's what a lot of Python scripts do on their shebang
> line.

Interesting, but changing the shebang doesn't solve the OP's problem.
He wants people to upload CGI scripts and just run them.

Of course it isn't as simple as "someone make up their mind where
perl is installed", because that someone doesn't exist.  Instead,
a lot of people have made up their minds in various ways.

Put symlinks to your perl in every sensible and semi-sensible location
that crops up.  That should limit complaints quickly.  Personally,
I'd draw a line at linking to "perl\r", but that is up to you.

Anno


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

Date: Wed, 04 Jul 2001 19:39:26 +0200
From: Philip Newton <pne-news-20010704@newton.digitalspace.net>
Subject: Re: two changes
Message-Id: <1pj6ktom61e43krdj6moc7gbcbt4vgtkpe@4ax.com>

On 4 Jul 2001 15:41:54 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
Siegel) wrote:

> Interesting, but changing the shebang doesn't solve the OP's problem.

Why not?

> He wants people to upload CGI scripts and just run them.

It sounded as if he had control over the CGI scripts, as though they
came from him:

: I default my CGI scripts to /usr/local/bin/perl.

I presume this means "I put a shebang line including
#!/usr/local/bin/perl in my CGI scripts". So if he "defaulted his CGI
scripts" to "#!/usr/bin/env perl" instead, they should work everywhere
that has a perl in the $PATH, wherever they're uploaded. Unless I'm
missing something.

> Put symlinks to your perl in every sensible and semi-sensible location
> that crops up.  That should limit complaints quickly.

Well, sort of; on one shell account I have, /usr/bin/perl and
/usr/local/bin/perl *both* exist, but one's the system-supplied 5.004,
and the other is a hand-compiled 5.005_03. I'd prefer the 5.005_03 that
the administrators compiled (since it's newer). Symlinking doesn't
really help here, since both versions can't share the same pathname, but
they presumably had their reason for not completely replacing the
existing /usr/bin/perl.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Wed, 4 Jul 2001 12:55:24 -0500
From: Reuben Logsdon <rlogsdon@io.com>
Subject: Re: two changes
Message-Id: <Pine.LNX.4.33.0107041251210.29266-100000@fnord.io.com>

On Wed, 4 Jul 2001, Rasputin wrote:
>
> > Also, could somebody make Unix Perl be forgiving about Perl CGI scripts
> > that have been uploaded in binary mode from a Windows machine?
>
> ??? Surely after years of getting errors, you've learned how to upload
> in ASCII mode?

Yes, I know how to use ASCII now.  I was writing on behalf of my
customers, who do not always use ASCII (and who call me when things
fail).

Anyway, thanks to everyone for their very good ideas about working around
these problems.  I think I'll switch my default back to /usr/bin/perl and
use some flags like -wT to work around the binary issue.   And save the
files with bare \n endings in the first place.

Thanks,
Reuben Logsdon




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

Date: Wed, 04 Jul 2001 13:16:41 GMT
From: Joonas Paalasmaa <joonas.paalasmaa@nokia.com>
Subject: Re: Using functions inside regular expressions
Message-Id: <3B431693.172098DE@nokia.com>

Kevin Michael Vail wrote:
> 
> In article <3B430D33.80A4AED5@nokia.com>, Joonas Paalasmaa
> <joonas.paalasmaa@nokia.com> wrote:
> 
> > How can I use functions inside regular expressions.
> >
> > For example if I want to reverse a match with reverse function.
> >
> >
> > Can I do something like in dummy example below?
> >
> > s/(?<= )(.*)(?= )/reverse($1)/eg;
>                                 ^
> 
> Yes, with the added character, which tells Perl to treat the
> replacement string as an expression.

Thanks!


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

Date: Wed, 04 Jul 2001 14:53:24 +0100
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: Using functions inside regular expressions
Message-Id: <3B431FD4.4860F1D0@bms.umist.ac.uk>

Joonas Paalasmaa wrote:
> 
> How can I use functions inside regular expressions.
> 
> For example if I want to reverse a match with reverse function.
> 
> Can I do something like in dummy example below?
> 
> s/(?<= )(.*)(?= )/reverse($1)/g;

Yes, if you use the e modifier.

s/(?<= )(.*)(?= )/reverse($1)/eg;

have a look at perldoc perlretut for more details.

HTH

Paul


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

Date: Wed, 4 Jul 2001 09:26:46 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Using functions inside regular expressions
Message-Id: <slrn9k66cm.d2f.tadmc@tadmc26.august.net>

Joonas Paalasmaa <joonas.paalasmaa@nokia.com> wrote:
>Kevin Michael Vail wrote:
>> In article <3B430D33.80A4AED5@nokia.com>, Joonas Paalasmaa
>> <joonas.paalasmaa@nokia.com> wrote:
>> 
>> > How can I use functions inside regular expressions.

>> > s/(?<= )(.*)(?= )/reverse($1)/eg;


Note that you are *not* using functions inside of regular 
expressions there!

   perldoc perlop

and note that it says:

   =item s/PATTERN/REPLACEMENT/egimosx


You wanted to know how to use functions in the _replacement_,
not in a regular expression (pattern).


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


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

Date: 4 Jul 2001 17:11:20 GMT
From: Randy Kobes <randy@theoryx5.uwinnipeg.ca>
Subject: Re: XS and perlcrt
Message-Id: <9hvino$5a4$1@canopus.cc.umanitoba.ca>

In comp.lang.perl.misc, Florian Albrecht <Florian.Albrecht@alcatel.de> wrote:
> Hi,

> I am working through perlXStut and I got an error by using nmake at the
> first example and got the error message below. I am using WinNT with
> ActiveState Perl5.6 an MSVC++ 5.0! What's my mistake? Perl -V:libc shows
> msvcrt.lib and I also looked for perlcrt.lib, but I didn't found it on
> my system. So I downloaded something from
> http://www.perl.com/CPAN-local/modules/by-authors/id/D/DO/DOUGL/. But
> did not help anything! :(

> Any ideas? Thanx in advance!

> ;-) Florian

> -- snip --

> link -out:blib\arch\auto\Mytest\Mytest.dll -dll -nologo -nodefaultlib
> -release  -libpath:"C:\Perl\lib\CORE"  -machine:x86 Mytest.obj  
> C:\Perl\lib\CORE\perl56.lib oldnames.lib kernel32.lib user32.lib
> gdi32.lib winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib
> oleaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib 
> version.lib odbc32.lib odbccp32.lib msvcrt.lib -def:Mytest.def

> C:\Perl\lib\CORE\perl56.lib : fatal error LNK1106: Ungueltige Datei oder 
> Datentraeger voll: Positionieren auf 0x3a3d3dba nicht moeglich
> NMAKE : fatal error U1077: 'link' : Rckgabe-Code '0xc'

My German's not so good, but I believe this message arises because
you're using VC++ 5, and ActiveState's perl56.lib was compiled
with VC++ 6. Can you upgrade to VC++ 6? If not, you could compile
your own perl with your VC++ 5. I've also heard that Microsoft's
SDK contains a linker that will work across VC++ versions.

best regards,
randy kobes


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

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.  

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 1245
***************************************


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