[18678] in Perl-Users-Digest
Perl-Users Digest, Issue: 846 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 7 09:06:50 2001
Date: Mon, 7 May 2001 06:05:09 -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: <989240709-v10-i846@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 7 May 2001 Volume: 10 Number: 846
Today's topics:
Re: automating ftp download using perl <www@nospam.com>
Re: cgi inter-process nobull@mail.com
Re: fork, glibc and weirdness <jfreeman@tassie.net.au>
Re: getting line by line from $ <www@nospam.com>
Re: Good editor for perl <pne-news-20010507@newton.digitalspace.net>
Re: Help on optimization wanted (Anno Siegel)
Re: Help with double hash of arrays nobull@mail.com
How to use Unicode::XX correctly ? <Unknown>
Re: Peculiar output from 'top' command <djberge@uswest.com>
Re: Perl & ODBC <bart.lateur@skynet.be>
Re: perl weirdness nobull@mail.com
Re: perl weirdness <jfreeman@tassie.net.au>
Re: Problem with the subroutine (closure?) for the "sor (EED)
Re: Problem with the subroutine (closure?) for the "sor (EED)
Re: Problem with the subroutine (closure?) for the "sor <joe+usenet@sunstarsys.com>
Re: Problem with the subroutine (closure?) for the "sor nobull@mail.com
Re: Problem with the subroutine (closure?) for the "sor nobull@mail.com
Re: redirect to a url & avoiding hacks <tinamue@zedat.fu-berlin.de>
Re: regular expression nobull@mail.com
Re: Rename subdirectories and files nobull@mail.com
Re: Rename subdirectories and files nobull@mail.com
Simple Regex (BUCK NAKED1)
Re: Simple Regex <peter.sogaard@tjgroup.com>
Re: Simple Regex <bart.lateur@skynet.be>
Re: Simple Regex nobull@mail.com
Re: Simple Regex <carlos@plant.student.utwente.nl>
Re: Simple Regex <bart.lateur@skynet.be>
Re: Simple Regex nobull@mail.com
Re: Trying to fill in a Pager Web page. nobull@mail.com
Re: unicode support in perl 5.6 -- I'm trying to get it <eike.grote.extern@fmis.de>
Re: UPPERCASE to <bart.lateur@skynet.be>
Re: What is the best module... <mk@ticklets.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 07 May 2001 08:15:24 GMT
From: "Perlzagame" <www@nospam.com>
Subject: Re: automating ftp download using perl
Message-Id: <wQsJ6.123579$xN4.7913560@news1.sttls1.wa.home.com>
just use a batch file...unless you WANT to learn perl.
"Dilmeet Kohli" <dkohli@san.rr.com> wrote in message
news:RYoJ6.1340$Tl2.915897@typhoon.san.rr.com...
> Hi everyone:
>
> I want to write a perl script to automatically down load files from ftp
> sites. I am sure I am not the first one. Wondering if similar scripts are
> available on the Internet. Please help me with some reference material.
>
> Thanks
> Dilmeet
>
>
------------------------------
Date: 07 May 2001 09:58:23 +0100
From: nobull@mail.com
Subject: Re: cgi inter-process
Message-Id: <u9u22xpmc0.fsf@wcl-l.bham.ac.uk>
"alik blochin" <alikbm@tx.technion.ac.il> spams:
> help is needed urgently..
That does not justify spamming, or failing to check the FAQ.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Mon, 07 May 2001 22:29:52 +1000
From: James Freeman <jfreeman@tassie.net.au>
Subject: Re: fork, glibc and weirdness
Message-Id: <3AF69540.B5FCBAF1@tassie.net.au>
Guy Smith wrote:
> "James freeman" <jfreeman@tassie.net.au> wrote in message
> news:3AF62B12.3154EE9F@tassie.net.au...
> >
> >
> > Guy Smith wrote:
> >
> > > I am trying to get a 3rd party package working. The package includes:
> > >
> > > 1) An executable program (compiled C++)
> > > 2) A PERL wrapper (Linkpoint cc auth software) that forks the
> executable
> > >
> > > When I run the executable from command line I receive no errors. When
> it is
> > > forked from the PERL wrapper I get:
> > >
> > > "error in loading shared libraries: /usr/local/linkpoint/lbin: symbol
> > > gethostbyname_r, version GLIBC_2.1.2 not defined in file libc.so.6 with
> link
> > > time reference"
> > >
> > > So, now I get to show my ignorance. I'm betting the executable receives
> the
> > > link references from the parent. However, I built this version of PERL
> > > (5.6.0) on the same system and the libs were 2.1.3, not 2.1.2.
> > >
> > > I'm not sure what to check/correct. I do not have the source to the
> > > executable.
> > >
> > > ENV: RedHat 6.2
> > > glibc 2.1.3
> > > PERL 5.6.0
> >
> > Need to see wrapper to comment. If executable is fine as you say wrapper
> holds
> > key. No wrapper, no realistic comments possible.
> >
> > James
> >
>
> That's not possible as the wrappers are copyrighted and have
> non-distribution clauses. Scanning the code I can say the child process
> creation is pretty straight forward. There is a $pid = fork() followed by
> an exec() with the path to the executable passed.
Suggest you try product support then
James
------------------------------
Date: Mon, 07 May 2001 08:12:33 GMT
From: "Perlzagame" <www@nospam.com>
Subject: Re: getting line by line from $
Message-Id: <RNsJ6.123568$xN4.7913305@news1.sttls1.wa.home.com>
I use this all the time to retrieve date from another server.
just convert $source to an array:
@newarray = split(/\n/,$source);
now use the array as you would in the local file.
<hope this is what you were looking for.
"Robert Wedge" <RWEDGE@webtv.net> wrote in message
news:23522-3AF62BC4-256@storefull-623.iap.bryant.webtv.net...
> I am trying to display the source of a remote file line by line.
>
> I can do it in a local file :
>
> open(INFO, $file);
> @lines = <INFO>;
> close(INFO);
> $lines = @lines;
>
> $count = 0;
> foreach $lines (@lines) {
> $count++;
> print "<li><xmp>$lines</xmp>";
> }
>
> I can get the source of a remote file in a scaler and print it out, but
> do not know how to break it down line by line.
>
> use LWP::Simple;
> use LWP::UserAgent;
> use URI::URL;
> $source = get($url);
>
> How can I get a numbered line by line print out of $source or convert it
> to an array to do the same?
> Thanks for any help on this.
> /Bob
>
------------------------------
Date: Mon, 07 May 2001 10:58:00 +0200
From: Philip Newton <pne-news-20010507@newton.digitalspace.net>
Subject: Re: Good editor for perl
Message-Id: <brocft08gvpd8a3q5fd0k1g968m9a8hnko@4ax.com>
On Sun, 6 May 2001 18:19:25 -0700, "Michael Cook"
<mikecook@cigarpool.com> top-posted:
> Try cygwin (a UNIX emulator for windoze - link below) and use vim - cygwin
> is free & you can do a lot more than text editing (with syntax coloring of
> course)...
Vim (and its graphical version, gvim) runs just fine under plain
Win32; you don't need Cygwin if you're just going to use vim.
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: 7 May 2001 07:54:18 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Help on optimization wanted
Message-Id: <9d5kba$jtu$1@mamenchi.zrz.TU-Berlin.DE>
According to Abigail <abigail@foad.org>:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCCVI
> September MCMXCIII in <URL:news:9d5275$879$1@mamenchi.zrz.TU-Berlin.DE>:
> ][ According to Abigail <abigail@foad.org>:
> ][ > Craig Berry (cberry@cinenet.net) wrote on MMDCCCV September MCMXCIII in
> ][ > <URL:news:tfb5nd19910l1d@corp.supernews.com>:
> ][ > }}
> ][ > }} #!/usr/bin/perl -w
> ][ > }} # sieve - find primes using a sieve
> ][ > }} # Craig Berry (20010506)
> ][ > }}
> ][ > }} use strict;
> ][ > }}
> ][ > }} my $max = shift || 100;
> ][ > }} my $limit = int sqrt($max);
> ][ > }} my @sieve = (0, 0, (1) x ($max - 1));
> ][ >
> ][ > That takes a lot of memory.
> ][ >
> ][ > Here's a sieve that uses approx. 1 byte/20 numbers:
> ][
> ][ [delightful code snipped]
> ][
> ][ Thanks for the thorough analysis. I like the way to save space
> ][ by skipping the numbers in each decade that can't be primes.
> ][
> ][ This particular method seems to be inspired by the decimal number
> ][ system. Could a different base inspire a system that saves even
> ][ more? A base that is the product of the first few primes looks
> ][ promising, but I get the distinct feeling I'm re-inventing some
> ][ wheel here. Off to the literature I go, instead of perpetrating
> ][ more off-topic ruminations.
>
>
> Base 30, being the lcm of 2, 3, 5 seems an obvious choice. But I
> was looking for a balance between saving memory and keeping the code
> simple and efficient. You don't want to make your inner loop too large;
> I'm already no happy with the 'next if' statement. Perhaps some loop
> unrolling in combination with Duff's device will make it fast.
I'll have to think about that. For the moment, I'd like to add to the
enjoyment with this table (the two columns under "saved" show how many
numbers in an interval [n*base, (n+1)*base) are known non-primes and
their percentage):
base saved primes used
2 1 50% (2)
6 4 67% (2, 3)
30 22 73% (2, 3, 5)
210 162 77% (2, 3, 5, 7)
2310 1830 79% (2, 3, 5, 7, 11)
30030 24270 81% (2, 3, 5, 7, 11, 13)
10 6 60% (2, 5)
It shows the savings over a one-to-one representation for some
bases that are products of small primes. Not unexpectedly there
are diminishing returns. In addition, the mapping between bits
in the sieve and the numbers they represent becomes more complex
with large bases. I thought that pre-computing a lookup-table
and a list of offsets could solve this, but I may be wrong.
Anno
------------------------------
Date: 07 May 2001 10:10:09 +0100
From: nobull@mail.com
Subject: Re: Help with double hash of arrays
Message-Id: <u9oft5plse.fsf@wcl-l.bham.ac.uk>
Benjamin Goldberg <goldbb2@earthlink.net> writes:
> or another way to make a copy:
> @$somehash{key1}{key2} = @somearray;
Syntax error. You forgot the {}
> Or maybe:
> push @$somehash{key1}{key2} $_ foreach(@somearray);
Syntax error. You forgot the {} and also the comma.
> Ok, now I'm being silly :)
Yep.
> but just remember, TINOTW.
TINOTW?
How does this expand to "there are an infinite number of ways to fail
to do it"?
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 2 May 2001 04:21:21 -0700 (PDT)
From: Unknown <Unknown>
Subject: How to use Unicode::XX correctly ?
Message-Id: <2.988799861959@iw0.mailusenet.com>
I'm trying to convert one encoding through utf16 to utf8
for example,BIG5 -> utf8. The way I did is like this
use Unicode::Map ;
use Unicode::String qw(utf8 utf16);
$Map = new Unicode::Map ;
$src="ä½ å¥½";
$dest = $Map -> to_unicode ("BIG5",$src);
#print $dest, "\n";
$dest=utf16($dest);
print $dest->utf8;
It works.My question is
1.What if the string is mixed language.
For example,"hello,ä½ å¥½".The code above will ignore the
English part,why?
2.Can I use Unicode::String only to do the same thing.I tried
to initialize the $src by utf7,utf16 but failed all the way.Can I
set the locale to BIG5 as Unicode:Map?What did I miss ?
Thanks for help.
Derek
----
Posted via http://www.etin.com - the FREE public USENET portal on the Web
Complete SEARCHING, BROWSING, and POSTING of text and BINARY messages!
------------------------------
Date: Mon, 07 May 2001 07:56:46 -0500
From: "Mr. Sunray" <djberge@uswest.com>
Subject: Re: Peculiar output from 'top' command
Message-Id: <3AF69B8E.99F9FDA@uswest.com>
Greg Andrews wrote:
> "Mr. Sunray" <djberge@uswest.com> writes:
> >
> >I'm doing some system monitoring by sending the output of the 'top'
> >command to a web page via CGI.pm. For now, I'm just trying to print the
> >headers (PID, USER, etc) into an HTML table. When sent to the command
> >line, the headers appear as expected. When sent to the web page, I'm
> >getting two anomalies.
> >
> >The first result is showing up in the web page as "[7m" - I've no idea
> >what that is
> >The last result is showing up as "COMMAND[K[m" - The 'COMMAND' is
> >correct, but what are those end characters?
> >
>
> Those are top's cursor movement sequences. It thinks it's sending
> its output to a terminal screen, so it's sending the terminal's
> screen formatting codes instead of plain text with space characters
> to separate the different fields.
>
> >...
> >if($^O eq "solaris"){ @results = `top -n 10` }
> >else{ @results = `top -n 1` }
> >
>
> I used a different approach. I used the pipeline form of the open()
> function to read top's output via a file descriptor:
>
> $topcommand = '/usr/bin/top -n all';
> open(TOP, "$topcommand |") || die "Can't run top: $!\n";
> while (<TOP>) {
> # parsing of top's header and
> # list of processes here
> }
>
> The fact that top's stdout was piped to my script rather than
> going to a terminal (or being captured by backquotes) seemed to
> convince top that it shouldn't use terminal escape sequences in
> its display.
>
> My particular script grabbed certain parts of top's header for
> things like the load average and total number of processes.
> It also parsed top's process list to count certain processes
> that I wanted to track (number of sendmails, number of httpds,
> stuff like that). That's why I told top to list all processes
> instead of just the top ten.
>
> Hope this helps,
>
> -Greg
> --
> +++++ Greg Andrews +++ gerg@panix.com +++++
> I have a map of the United States that's actual size
> -- Steven Wright
Thanks Greg. I'll use this instead. I'm surprised that 'top' for Linux has
this limitation, though I was just as surprised to learn that 'top' wasn't
part of SVR4 given how prolific it is. The only other suggestions
I received were to pipe it through 'head' or 'tail', which was not only
kinda clunky in my mind, but usually resulted in "broken pipe" errors.
Regards,
Mr. Sunray
------------------------------
Date: Mon, 07 May 2001 10:44:30 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Perl & ODBC
Message-Id: <2kucfto0n4c6f8ekau1106s1h2oc0aabl1@4ax.com>
jtjohnston wrote:
>Can I use and access Microsoft Access *.mdb files without having a sql
>server?
>For example, I was consulting this:
> http://www.geocities.com/Area51/Cavern/4503/perl_odbc.htm
>But it talks about a SQL server acting as an intermediary. I'm sure I've
>seen this done without a SQL server?
Sure. I assume your talking about your own humble PC?
First, install the Windows ports of DBI and DBD::ODBC. You can get them
from <http://www.activestate.com/PPMpackages/5.6/> and its
"MSWin32-x86-multi-thread" subdirectory (for 5.6.0).
Second, open the Control Panel, and select "ODBC Data Sources". Choose
"System DSN", and click "Add". Select the Access driver, and you'll get
into a "ODBC Microsoft Access Setup" dialog. There, you can pick an
existing *.mdb file. You give it a "Data Source Name" (DSN), click OK,
and you're done.
Now, you should be able to connect to the database from within a Perl
script. The connect string ($data_source in the DBI docs) can be a
simple "DBI:ODBC:$dsn", where $dsn contains the DSN name you entered in
the dialog above. That's basically it.
--
Bart.
------------------------------
Date: 07 May 2001 10:23:08 +0100
From: nobull@mail.com
Subject: Re: perl weirdness
Message-Id: <u9lmo9pl6r.fsf@wcl-l.bham.ac.uk>
Steve Wilbur <ultramafic1@yahoo.com> writes:
> Ive been banging my head on this to no avail - i'm hoping someone can
> help.
>
> Consider the following routine:
What routine? I see no routine? A routine would imply something that
would pass syntax check. If you are getting results you consider
unexpected then it is probably the result of something you do not
understand.
> i'm at a loss. ideas are appreciated. tia. (:
We have no idea what your code looks like.
Once we fix the typos in that you've posted so that it would compile
it would not behave as you describe.
Please post actual complete code that we could run to reproduce the
symptoms you describe.
BTW: It very rarely[1] makes sense to define a subroutine with a protype
saying it takes no arguments and then call it with the prototype
handling disabled so as to force it to take arguments after all.
That is what you appear to be doing, but then again that could just be
an aritfact of the transcription errors.
[1] I've done something like this once.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Mon, 07 May 2001 23:07:05 +1000
From: James Freeman <jfreeman@tassie.net.au>
Subject: Re: perl weirdness
Message-Id: <3AF69DF9.5F155A28@tassie.net.au>
Steve Wilbur wrote:
> Ive been banging my head on this to no avail - i'm hoping someone can
> help.
>
> Consider the following routine:
>
> sub build_page()
> my (@contents)
> <blah, blah, blah>
> print(@contents);
> return(@contents);
>
> now consider this line:
>
> print(&build_page(@contents));
>
> in build_page(), when i print @contents, i see what i expect.
> however, with print(&buildpage(@contents)) i don't get anything, for
> some contents of @contents. for what it's worth:
>
> push(@results,&build_page()); print(@results);
>
> also gives me nothing, again, for some contents of @contents.
> @contents clearly contains what it is supposed to, but
> return(@contents) doesn't seem to be returning it in some instances.
>
> i'm at a loss. ideas are appreciated. tia. (:
Post valid perl not rubbish!
Run this, it should explain you problems:
#!usr/bin/perl
use strict;
my @contents =(1,2,3,4,5);
print "\@contents before sub call @contents\n";
print "\nDo \&build_page(\@contents);\n";
&build_page(@contents);
print "\@contents after call to sub @contents\n";
print "\nDo \@contents = \&build_page(\@contents);\n";
@contents = &build_page(@contents);
print "\@contents after call to sub with assignment of result
@contents\n";
print "\nDo print \&build_page(\@contents), etc\n";
print &build_page(@contents),"<<-- this is the result of
\&build_page(\@contents)\n\@contents is still @contents\n";
sub build_page {
my @contents = @_;
#do stuff to contents, let's increment each value by 1
foreach (@contents) {$_++}
print "Within sub after increment @contents\n";
return @contents;
}
James
>
>
> ultramafic1@yahoo.com
------------------------------
Date: Mon, 07 May 2001 09:05:57 +0200
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: Re: Problem with the subroutine (closure?) for the "sort"
Message-Id: <3AF64955.AA8A94ED@eed.ericsson.se>
nobull@mail.com wrote:
> > > If you want sort to use a comparison routine in another package then
> > > see thread "Using a comparison routine in another package" from last
> > > November or more recently "efficient comparators (namespaces for $a and
> > > $b)" a few weeks ago.
> >
> > Thanks but your solution looks really dirty :-(
>
> There is a clean (but slower) solution using @_[0,1] rather than $a,$b
> too but since as far as I can see you are not using a comparison routine
> in another package so the issue does not arrise.
Unfortunately I do.
------------------------------
Date: Mon, 07 May 2001 09:11:35 +0200
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: Re: Problem with the subroutine (closure?) for the "sort"
Message-Id: <3AF64AA7.DF4FDFE0@eed.ericsson.se>
nobull@mail.com wrote:
> Now here's an odd thing... the subject of this thread has now mutated
> to so that it _does_ now match the subject line!
To change the subject of the thread again:
> "Alexander Farber (EED)" <eedalf@eed.ericsson.se> writes:
>
> > if ($path =~ /\/(\w+)$/) # sort by string in PATH_INFO
> > {
> > return sub { $hohref -> {$a} -> {$1} cmp $hohref -> {$b} -> {$1} };
> > }
>
> $1 is a global variable. This means that when the subroutine is
> executed it will use whatever value happens to be in $1 at the time.
> This is no good as you want the closure to remeber the string that was
> found in the regex. You must use a lexical variable instead.
>
> if (my ($sortkey) = $path =~ /\/(\w+)$/) # sort by string in PATH_INFO
Isn't this dangerous because of the
http://www.perl.com/pub/2000/05/p5pdigest/THISWEEK-20000521.html#my_x_if_0;_Trick
> {
> return sub { $hohref -> {$a} -> {$sortkey} cmp $hohref -> {$b} -> {$sortkey} };
> }
------------------------------
Date: 07 May 2001 03:29:09 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Problem with the subroutine (closure?) for the "sort"
Message-Id: <m3oft51ut6.fsf@mumonkan.sunstarsys.com>
"Alexander Farber (EED)" <eedalf@eed.ericsson.se> writes:
> nobull@mail.com wrote:
> > > > If you want sort to use a comparison routine in another package then
> > > > see thread "Using a comparison routine in another package" from last
> > > > November or more recently "efficient comparators (namespaces for $a and
> > > > $b)" a few weeks ago.
> > >
> > > Thanks but your solution looks really dirty :-(
> >
> > There is a clean (but slower) solution using @_[0,1] rather than $a,$b
> > too but since as far as I can see you are not using a comparison routine
> > in another package so the issue does not arrise.
>
> Unfortunately I do.
I don't know if this was discussed in those threads, but if your
comparator lies in a different package/module, all you need to do is
export *a and *b:
#!/usr/bin/perl -wl
use strict;
package Foo;
use Exporter;
use base 'Exporter';
BEGIN{ @Foo::EXPORT = qw/*a *b/ }
my $compare = sub { $b <=> $a }; # $a and $b in package Foo
package main;
BEGIN { Foo->import() } # analog of "use Foo;"
print sort $compare 1..9;
__END__
output:987654321
--
Joe Schaefer "A foolish consistency is the hobgoblin of little minds, adored
by little statesmen and philosophers and divines."
-- Ralph Waldo Emerson
------------------------------
Date: 07 May 2001 09:46:00 +0100
From: nobull@mail.com
Subject: Re: Problem with the subroutine (closure?) for the "sort"
Message-Id: <u9zocppmwn.fsf@wcl-l.bham.ac.uk>
"Alexander Farber (EED)" <eedalf@eed.ericsson.se> writes:
> nobull@mail.com wrote:
> > > > If you want sort to use a comparison routine in another package then
> > > > see thread "Using a comparison routine in another package" from last
> > > > November or more recently "efficient comparators (namespaces for $a and
> > > > $b)" a few weeks ago.
> > >
> > > Thanks but your solution looks really dirty :-(
> >
> > There is a clean (but slower) solution using @_[0,1] rather than $a,$b
> > too but since as far as I can see you are not using a comparison routine
> > in another package so the issue does not arrise.
>
> Unfortunately I do.
Then you must either share $a,$b between the packages (quich and
dirty) or use the other (clean but slow) comparitor calling convention
(see "perldoc -f sort").
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 07 May 2001 09:42:23 +0100
From: nobull@mail.com
Subject: Re: Problem with the subroutine (closure?) for the "sort"
Message-Id: <u93dahr1n4.fsf@wcl-l.bham.ac.uk>
"Alexander Farber (EED)" <eedalf@eed.ericsson.se> writes:
> nobull@mail.com wrote:
> >
> > if (my ($sortkey) = $path =~ /\/(\w+)$/) # sort by string in PATH_INFO
>
> Isn't this dangerous because of the
> http://www.perl.com/pub/2000/05/p5pdigest/THISWEEK-20000521.html#my_x_if_0;_Trick
No, this is completely different.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 7 May 2001 11:36:33 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: redirect to a url & avoiding hacks
Message-Id: <9d61c1$gceug$3@fu-berlin.de>
Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
> Keith G wrote:
>> is this the best way to do this:
>> print $query->redirect('http://www.mypage.com/thepage.htm');
> This is your worst possible choice. You are using quarter of
> a megabyte of coding, well over six-thousand lines of code
> to accomplish what can be done in one line of code:
> print "Location: url/path/to/new/page";
hmm... didn't you forget something? at least four keystrokes?
>> any suggestions?
> Use of CGI.pm in almost all cases is massive overkill.
> Learn to how program
=) is this an advice to yourself?
> Doing this will teach you
> how to write fast, efficient scripts which are
> relatively bug free.
^^^^^^^^^^
hmmm...
ok, my suggestions if you wanna avoid using CGI.pm is,
print at least these three lines:
print <<EOM;
Status: 302 Moved
Location: url
EOM
hth,
tina
--
http://tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
please don't email unless offtopic or followup is set. thanx
------------------------------
Date: 07 May 2001 09:56:31 +0100
From: nobull@mail.com
Subject: Re: regular expression
Message-Id: <u9wv7tpmf4.fsf@wcl-l.bham.ac.uk>
ebohlman@omsdev.com (Eric Bohlman) writes:
> Benjamin Goldberg <goldbb2@earthlink.net> wrote:
> > With only one capture, this could also have been done
> > m[(pattern here)$]; $Rate = $1;
> > though it is probably silly to do so.
>
> Not just silly, but dangerous. If for some reason the pattern fails to
> match, $Rate will be set to whatever the last successful match had been.
> Not correct, and not easy to debug either.
I agree. There is nothing wrong with having a m// in your code that
you believe can only be reached under circumstances where if will
succeded. However, when you do so you should always append "or die".
This serves both as a comment to remind future maintainers of your
code that you believed the match would always succede and also as a
debugging aid should the match ever fail.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 07 May 2001 12:31:04 +0100
From: nobull@mail.com
Subject: Re: Rename subdirectories and files
Message-Id: <u94ruxpf9j.fsf@wcl-l.bham.ac.uk>
tadmc@augustmail.com (Tad McClellan) who is usually right on the ball[1]
uncharacteristically writes utter nonsense (again!):
> Arun Horne <a.b.horne@exeter.ac.uk> wrote:
>
> >all whitespace is replaced by _'s
>
> tr/\s//d;
No, that removes all occurances of the letter 's'.
> >each word in the filename is correctly capitalised, i.e. HeLLo becomes
> >Hello and jOb -> Job
>
> s/(.*)/\u\L$1/;
No, the OP said "each word".
> >Can anyone provide me with such code?
>
> Post to clpmisc for help with _writing_ Perl programs.
>
> Use a search engine for searching for programs.
Yes, right on.
Not getting enough sleep Tad?
[1] And usually the first to point out when I'm spouting nonsense.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 07 May 2001 12:33:42 +0100
From: nobull@mail.com
Subject: Re: Rename subdirectories and files
Message-Id: <u91yq1pf55.fsf@wcl-l.bham.ac.uk>
nobull@mail.com writes carelessly:
> s/(\w+)/\u\L\1/g
Opps! Deprecation warning: \1 better written as $1
s/(\w+)/\u\L$1/g
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Mon, 7 May 2001 02:36:53 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Simple Regex
Message-Id: <13525-3AF65095-30@storefull-246.iap.bryant.webtv.net>
How do I grab the part of a string from the last slash to EOL? for
example: if I want to replace "http://my.com/images/banner.gif" with
"banner.gif".
I tried
$name =~ s/\/(.*?)\n/(.*?)\n/e and it failed.
Thanks,
--Dennis
------------------------------
Date: Mon, 7 May 2001 10:57:21 +0200
From: "Peter Søgaard" <peter.sogaard@tjgroup.com>
Subject: Re: Simple Regex
Message-Id: <9d5o1o$1vn9$1@tnews.inet.tele.dk>
$name =~ s/^.*?\/([^\/]*?)$/$1/;
"BUCK NAKED1" <dennis100@webtv.net> wrote in message
news:13525-3AF65095-30@storefull-246.iap.bryant.webtv.net...
> How do I grab the part of a string from the last slash to EOL? for
> example: if I want to replace "http://my.com/images/banner.gif" with
> "banner.gif".
>
> I tried
> $name =~ s/\/(.*?)\n/(.*?)\n/e and it failed.
>
> Thanks,
> --Dennis
>
------------------------------
Date: Mon, 07 May 2001 09:05:43 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Simple Regex
Message-Id: <13pcft8ckm16r01le34ohr64pg28a3h7na@4ax.com>
BUCK NAKED1 wrote:
>How do I grab the part of a string from the last slash to EOL? for
>example: if I want to replace "http://my.com/images/banner.gif" with
>"banner.gif".
>
>I tried
>$name =~ s/\/(.*?)\n/(.*?)\n/e and it failed.
For a start, your string probably doesn't contain a newline. So use "$"
instead.
But not here and now.
And you don't want that "e", the right hand side is not per lcode, but
some sort of string.
What you wrote would probably, as a valid regex, have to be:
s/\/(.*?)$/$1/;
except that this will match everything from the first slash till the end
of the string, question mark or no question mark, and replace everything
by itself except for that slash. Non-greediness is no good once the
starting point and ending point of a match are determined.
You can try and match everything up to a slash in a greedy manner, and
delete it. That will match everything up to the *last* slash. What you
want to keep would be unharmed.
s/.*\///;
or
s!.*/!!;
--
Bart.
------------------------------
Date: 07 May 2001 10:38:15 +0100
From: nobull@mail.com
Subject: Re: Simple Regex
Message-Id: <u9itjdpkhk.fsf@wcl-l.bham.ac.uk>
dennis100@webtv.net (BUCK NAKED1) writes:
> How do I grab the part of a string from the last slash to EOL?
my ($last_part) = $a_string =~ m{/([^/]*)$} or die "There was no slash";
> for
> example: if I want to replace "http://my.com/images/banner.gif" with
> "banner.gif".
This is a different question.
> I tried
> $name =~ s/\/(.*?)\n/(.*?)\n/e and it failed.
You appear to be trying random things. You appear to have too many
misconceptions that simply telling you the answer is unlikely to help
you at all.
I suggest you go back and re-learn about Perl regex, s/// and m//.
The thing on the left of the s///e must be a regular expression
matching the _whole_ of the thing you want to replace.
The thing on the right of the s///e must be an Perl expression that
evaluates to what you want to replace the matched stuff with.
If you drop the /e then the thing on the right behaves as a double
quoted string. i.e. s/foo/bar/ is eqivalent to s/foo/"bar"/e
The thing on the right is not a regular expression.
Perl regular expressions always match as soon as possible, the
non-greedy qualifier does not alter this.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Mon, 7 May 2001 12:33:56 +0200
From: "carlos" <carlos@plant.student.utwente.nl>
Subject: Re: Simple Regex
Message-Id: <9d5tfl$nap$1@dinkel.civ.utwente.nl>
split /\//, $name; pop $name;
"BUCK NAKED1" <dennis100@webtv.net> wrote in message
news:13525-3AF65095-30@storefull-246.iap.bryant.webtv.net...
> How do I grab the part of a string from the last slash to EOL? for
> example: if I want to replace "http://my.com/images/banner.gif" with
> "banner.gif".
>
> I tried
> $name =~ s/\/(.*?)\n/(.*?)\n/e and it failed.
>
> Thanks,
> --Dennis
>
------------------------------
Date: Mon, 07 May 2001 10:48:26 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Simple Regex
Message-Id: <scvcft8ev2vni6nfvob0ppu59u01fu2h6u@4ax.com>
nobull@mail.com wrote:
>my ($last_part) = $a_string =~ m{/([^/]*)$} or die "There was no slash";
Why don't you just drop that slash from the regex and it will never
fail.
--
Bart.
------------------------------
Date: 07 May 2001 12:10:45 +0100
From: nobull@mail.com
Subject: Re: Simple Regex
Message-Id: <u98zk9pg7e.fsf@wcl-l.bham.ac.uk>
Bart Lateur <bart.lateur@skynet.be> writes:
> nobull@mail.com wrote:
>
> >my ($last_part) = $a_string =~ m{/([^/]*)$} or die "There was no slash";
>
> Why don't you just drop that slash from the regex and it will never
> fail.
Because that's not what the OP asked for and would IMNSHO probably be
a latent bug.
The OP asked for how to grab the bit after the last slash. He did not
state what he wanted to happen if there was no slash. The obvious
choices are:
1) Return the whole original string
2) Return a null string
3) Throw an exception.
4) Return undef
In the absense of any other information I'd guess that the above are
presented in ascending order of likelyhood of being the "right thing"
(DWIM) to do.
I chose to implement 3 because had chosen to implement option 4 then
it would not have drawn the OP's attension to the fact that he needed
to consider what he wanted to do in the "no slash" case.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 07 May 2001 09:58:51 +0100
From: nobull@mail.com
Subject: Re: Trying to fill in a Pager Web page.
Message-Id: <u9r8y1pmb8.fsf@wcl-l.bham.ac.uk>
Kathy Ramsey <ramseyk@home.com> writes:
> I am trying to feed a pager # and message to www.arch.com - a pager web
> site.
> where do I begin!
LWP
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Mon, 07 May 2001 13:59:22 +0200
From: Eike Grote <eike.grote.extern@fmis.de>
Subject: Re: unicode support in perl 5.6 -- I'm trying to get it to work like
Message-Id: <3AF68E1A.8941C225@fmis.de>
Hi,
"Resnick, David" wrote:
>
[...]
> The brief "C" program that I'm trying to emulate in perl:
> /***********************************************************/
[...]
> if (iswalpha(w)) walpha++;
> if (iswdigit(w)) wdigit++;
> if (iswprint(w)) wprint++;
[...]
Ah, you're using the "wide character" functions...
[...]
> The results of this are as follows:
> Solaris NT
> isprint 45271 38888
> isdigit 20 192
> isalpha 36121 36150
[...]
> ###############################################################
[...]
> $alpha++ if (isalpha($letter));
> $print++ if (isprint($letter));
> $digit++ if (isdigit($letter));
[...]
Perl obviously uses the functions for "simple" characters
(at least with Solaris).
[...]
> I get the following results:
> Solaris NT
> isprint 86 55974
> isdigit 10 13
> isalpha 52 1298
You must use the "properties" \p{IsAlpha}, \p{IsDigit}, and
\p{IsPrint} for regexes (unfortunately this method produces
error messages for certain characters...):
### method (1)
$alpha++ if ($letter =~ /\p{IsAlpha}/);
$digit++ if ($letter =~ /\p{IsDigit}/);
$print++ if ($letter =~ /\p{IsPrint}/);
To test all chracters in one regex one could do:
### method (2)
my $t = '';
for ($i=0x0; $i<=0xffff; $i++) {
$letter = chr($i);
$t .= $letter;
}
$alpha = ($t =~ s/(\p{IsAlpha})/$1/g);
$digit = ($t =~ s/(\p{IsDigit})/$1/g);
$print = ($t =~ s/(\p{IsPrint})/$1/g);
Finally, one could examine the Perl's files about Unicode
'.../lib/5.6.1/unicode/Is/Alpha.pl',... (method (3)).
It is somewhat puzzling that nearly all methods yield
different results...:
| alpha digit print
--------------+----------------------------
your C code | 45963 20 55569
(1) | 46018 518 56592
(2) | 44671 788 56055
(3) | 46018 198 55568 (only chars <= 0xffff)
My configuration: Perl 5.6.1, Solaris 8 10/00
Eike
--
Eike Grote, ConSol GmbH
E-Mail: eike.grote@epost.de
------------------------------
Date: Mon, 07 May 2001 09:14:05 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: UPPERCASE to
Message-Id: <erpcftollj0lvhf3vge7uf9d9ve6kq1ee0@4ax.com>
Dan wrote:
>> my $text = lc do { local $/; <>; };
>> $text =~ s/((^|\.)\s*\w)/\U$1/g;
>
>This works relatively well, however, I don't want each new line to start
>capitalized.
...
>I want the first A to remain capitalized, but I don't want the "s" in Southern
>and the "a" in and to be capitalized. How could I modify the code to make this
>work?
It does already?
Look, you slurped in the whole text. You don't use the /m odifier.
Hence, /^/ means "start of string" and nothing else.
--
Bart.
------------------------------
Date: Mon, 7 May 2001 11:23:01 +0200
From: "Paul Kersey" <mk@ticklets.com>
Subject: Re: What is the best module...
Message-Id: <9d5pn3$90t$1@news1.xs4all.nl>
> what is the best module to encrypt/decrypt text files?
> everyone i have checked out can only encrypt 8 bits.
> and i need to encrypt files over 2KB
You could write functions which do encryptions of arbitrary sized text, by
splitting them up in 8 bits pieces like this....
in your script:
require imcry;
my $text = 'asfs fklsdjflksjdflk lskadfjlsakjdf asdjflkjsadflk
laskdflaskjdfl sadlfkj';
my $key = pack("H16", "0123456789ABCDEF");
my $encrypted = &imcry::encrypt($key,$text);
my $decrypted = &imcry::decrypt($key,$encrypted);
In this example I use Crypt::Blowfish, but you can use every encryption
module you like....
package imcry;
use strict;
use warnings;
use Crypt::Blowfish;
our $BLOCKSIZE = 8;
sub encrypt {
my ($key,$dat) = @_;
my $enc = '';
my $cipher = new Crypt::Blowfish $key;
if ($BLOCKSIZE > 0) {
my $l_dat = length($dat);
for (my $i=0; $i < $l_dat;$i+=$BLOCKSIZE) {
my $tmp = substr($dat,$i,$BLOCKSIZE);
my $tmp2 = sprintf("%-" . $BLOCKSIZE . "s",$tmp); #pad with spaces if
string not long enough
$enc .= $cipher->encrypt($tmp2);
}
}
else {
$enc .= $cipher->encrypt($dat);
}
return $enc;
}
sub decrypt {
my ($key,$dat) = @_;
my $dec = '';
my $cipher = new Crypt::Blowfish $key;
if ($BLOCKSIZE > 0) {
my $l_dat = length($dat);
for (my $i=0; $i < $l_dat;$i+=$BLOCKSIZE) {
my $tmp = substr($dat,$i,$BLOCKSIZE);
$dec .= $cipher->decrypt($tmp);
}
}
else {
$dec .= $cipher->decrypt($dat);
}
$dec =~ s/\s+$//; #remove trailing spaces
return $dec;
}
1;
------------------------------
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 846
**************************************