[19591] in Perl-Users-Digest
Perl-Users Digest, Issue: 1786 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 21 09:05:31 2001
Date: Fri, 21 Sep 2001 06:05: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: <1001077512-v10-i1786@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 21 Sep 2001 Volume: 10 Number: 1786
Today's topics:
Re: A couple of Win9x Perl questions rbishop@hursley.ibm.com
Re: a question about comments in perl nobull@mail.com
Re: Hash problem... <guardian@chello.be>
Re: How to get the path of current directory in perl news@roaima.demon.co.uk
Re: How to get the path of current directory in perl nobull@mail.com
Re: installing modules in WinNT <randy@theory.uwinnipeg.ca>
Re: Objects and Sockets <bart.lateur@skynet.be>
Re: Objects and Sockets (Martien Verbruggen)
Re: Objects and Sockets nobull@mail.com
Re: Objects and Sockets <bart.lateur@skynet.be>
Re: Perl English only?????? (Damian Conway)
Re: perl, lvalues, rvalues, and operators <iltzu@sci.invalid>
Re: perl, lvalues, rvalues, and operators <simon.oliver@umist.ac.uk>
Re: Pre spawning in perl (Anno Siegel)
Problem Dieing <alan@scotlpuk.com>
Re: Problems with $ character <jocke30_gbg@hotmail.com>
Re: Processing page between two other pages. (Phil Hibbs)
Re: regex effeciency question <Thomas@Baetzler.de>
Re: regex effeciency question nobull@mail.com
Re: Regular Expresion help needed <iltzu@sci.invalid>
Re: s/// modifies @_ ? <bart.lateur@skynet.be>
Re: Schwartzian Transform problem <iltzu@sci.invalid>
Re: Schwartzian Transform problem (Anno Siegel)
Re: search, replace, functions, text wrapping (hard que <please@no.spam>
String comparison (Samppa)
Re: String comparison (Martien Verbruggen)
Re: String comparison <simon.oliver@umist.ac.uk>
Re: String comparison <Thomas@Baetzler.de>
Re: String comparison <peb@bms.umist.ac.uk>
Re: Use symbol table like 'real' hash <bart.lateur@skynet.be>
Re: using a variable to call a function <peb@bms.umist.ac.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 21 Sep 2001 10:20:00 +0000 (UTC)
From: rbishop@hursley.ibm.com
Subject: Re: A couple of Win9x Perl questions
Message-Id: <9of48g$q8a$1@sp15at20.hursley.ibm.com>
I spend most of my time on Unix, but I recall from some time ago that
you can get hardware info by querying the registry (on checking an NT
box, look at
\\HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0
for info on your first processor). You can query the registry with a
number of perl modules.
------------------------------
Date: 21 Sep 2001 13:22:36 +0100
From: nobull@mail.com
Subject: Re: a question about comments in perl
Message-Id: <u9lmj8bunn.fsf@wcl-l.bham.ac.uk>
"Rene Scheibe" <Rene.Scheibe@gmx.net> writes:
> Can someone tell me how to not just comment out one line with # but
> a whole section?
FAQ: "How can I comment out a large block of perl code?"
You are supposed to check the FAQ _before_ you post.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 21 Sep 2001 11:17:48 GMT
From: "GuaRDiaN" <guardian@chello.be>
Subject: Re: Hash problem...
Message-Id: <wlFq7.1147$2a.62035@news.chello.be>
Ok now I have this to store the data
if ( $event1 = "killed" ) {
$$player_name{kills}{count}++; # Player kills
$$player_name{kills}{victim}{$player_name2}++;
$$player_name{kills}{weapon}{$noun2}++;
$$player_name2{death}{count}++; # Player death
$$player_name2{death}{killer}{$player_name}++;
$$player_name2{death}{weapon}{$noun2}++;
}
And this to retrieve data...
foreach $user ( keys %player ) {
print "$user\n";
print "### Kills: $$user{kills}{count}\n";
print "### Death: $$user{death}{count}\n";
print "\n";
}
But when I try do get the other infos... I got a syntax error...
Perl don't accept keys %player{kills}
I tried this:
foreach $key ( keys %player{kills} ) {
some print...
}
------------------------------
Date: 21 Sep 2001 11:17:59 GMT
From: news@roaima.demon.co.uk
Subject: Re: How to get the path of current directory in perl
Message-Id: <3bab13d7@news.netserv.net>
Merina <merigrace@rediffmail.com> wrote:
> I want to get the path of the current directory in a variable using perl?
require 'getcwd.pl';
$current_directory = &getcwd';
Chris
------------------------------
Date: 21 Sep 2001 13:26:23 +0100
From: nobull@mail.com
Subject: Re: How to get the path of current directory in perl
Message-Id: <u9itecbuhc.fsf@wcl-l.bham.ac.uk>
news@roaima.demon.co.uk writes:
> Merina <merigrace@rediffmail.com> wrote:
> > I want to get the path of the current directory in a variable using perl?
>
> require 'getcwd.pl';
> $current_directory = &getcwd';
I don't understand why you think the OP needs their code to run under
Perl4. (Under Perl5 getcwd.pl is superceeded by Cwd.pm).
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 21 Sep 2001 06:17:24 -0500
From: "Randy Kobes" <randy@theory.uwinnipeg.ca>
Subject: Re: installing modules in WinNT
Message-Id: <9of86n$4h$1@canopus.cc.umanitoba.ca>
"Eli the Bearded" <eli@there-is-no-more-qzto.com> wrote
in message news:eli$0109192215@qz.little-neck.ny.us...
> I'm not used to using perl on windows systems, so my problems might
> be naive, but....
>
> I got a recent ActiveState perl. I tried to install it on a WinNT
> box with pkunzip. That seemed to fail horribly, it mangled the
> filenames to 8.3 in a bad way. So I downloaded winzip and tried
> again. That seems to work, perl can find modules now.
>
> But ppm does not work. I need to install one non-standard module
> for an app to work: Time::HiRes.
>
> Tring to run 'ppm' interactively (or 'ppm query Time' or
> 'ppm install Time::HiRes' or downloading the Time::HiRes
> zip, extracting it, and running 'ppm Time-HiRes.ppd' or
> 'ppm install Time-HiRes.ppd') always gives me an error:
>
> Can't use an undefined value as a SCALAR reference at
> C:/Perl/ActivePerl/Perl/site/lib/PPM.pm line 1636 <DATA> line 40.
I think, if you're not using the MSI binary, there's an 'install.bat'
(or something like that) that comes with the distribution that,
when run, will configure ppm, among other things.
best regards,
randy kobes
------------------------------
Date: Fri, 21 Sep 2001 11:56:37 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Objects and Sockets
Message-Id: <lmamqtolkk7fn4oeiv0j260t90mc0v9caa@4ax.com>
nobull@mail.com wrote:
>You should stop using old Perl4-style naked filehandles.
>
>socket(my $session, PR_INET, SOCK_STREAM, getprotobyname('tcp')) || die "$!";
Only works from 5.6.0 on. Many servers still use 5.005_xx.
--
Bart.
------------------------------
Date: Fri, 21 Sep 2001 22:25:18 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Objects and Sockets
Message-Id: <slrn9qmcde.738.mgjv@martien.heliotrope.home>
On 19 Sep 2001 13:18:30 +0100,
nobull@mail.com <nobull@mail.com> wrote:
> delanthear@yahoo.com (Del) writes:
>
>> Could you point me to a working example so I can get my head
>> around it?
>>
>> eg,
>> socket(SESSION, PR_INET, SOCK_STREAM, getprotobyname('tcp')) || die
>> "$!";
>>
>> creates a socket, usable by the filehandle SESSION, but how would I
>> store that within the object for later use?
>
> You should stop using old Perl4-style naked filehandles.
>
> socket(my $session, PR_INET, SOCK_STREAM, getprotobyname('tcp')) || die "$!";
perl 4 style? Have you tried the above on a Perl version like 5.005_03?
Those handles were in use for some 5 1/2 years, _after_ perl 4 became
obsolete, and are still used in many places.
> You can now use the scalar variable $session in place of the bare
> filehandle SESSION and you can also store its value in an object.
>
> Note: The GLOBref autovivification used above only works in 5.6 and
> later. In eariler 5.x Perls you would need to use explicitly create a
> GLOBref before you call socket().
Ah, you were aware of that. Then why the almost insulting 'Perl4-style'?
Or didn't you mean it the way it reads?
> Of course, it would be better still to drop all the Perl4-style socket
> IO and use IO::Socket.
And again, the Perl4-style remark.
Agreed on the IO::Socket though.
Martien
--
Martien Verbruggen |
Interactive Media Division | Failure is not an option. It comes
Commercial Dynamics Pty. Ltd. | bundled with your Microsoft product.
NSW, Australia |
------------------------------
Date: 21 Sep 2001 13:29:51 +0100
From: nobull@mail.com
To: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Objects and Sockets
Message-Id: <u9g09gbubk.fsf@wcl-l.bham.ac.uk>
Bart Lateur <bart.lateur@skynet.be> writes:
> nobull@mail.com wrote:
>
> >You should stop using old Perl4-style naked filehandles.
> >
> >socket(my $session, PR_INET, SOCK_STREAM, getprotobyname('tcp')) || die "$!";
>
> Only works from 5.6.0 on. Many servers still use 5.005_xx.
Eh, yes, and you'll note that directly after the line you quote I
explain the work-round for 5.5.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 21 Sep 2001 12:52:39 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Objects and Sockets
Message-Id: <ksdmqtoet7k2j4iqj60835m2aeqlruqpo5@4ax.com>
nobull@mail.com wrote:
>> >socket(my $session, PR_INET, SOCK_STREAM, getprotobyname('tcp')) || die "$!";
>>
>> Only works from 5.6.0 on. Many servers still use 5.005_xx.
>
>Eh, yes, and you'll note that directly after the line you quote I
>explain the work-round for 5.5.
It's an ugly workaround; far too low level. I prefer a "new FileHandle"
for this.
--
Bart.
------------------------------
Date: 21 Sep 2001 12:34:09 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: Perl English only??????
Message-Id: <9ofc3v$95t$1@towncrier.cc.monash.edu.au>
Chris Stith <mischief@velma.motion.net> asked:
> What has creating 'Lingua-Romana-Perligata' pointed out to you,
> Damian, that would be good to share with the rest of us?
I learnt a huge amount from designing and implementing a Latin binding
of Perl. Specifically:
- That positional syntax isn't nearly as fundamental a notion
as the language design literature would have you believe.
- That our reliance of fixed syntaxes actually contributes
to common novice errors, and discriminates against people
with certain common cognitive approaches.
- That Perl has a deeper semantic structure that is far more
consistent than its postmodern syntax would suggest.
- That there are unexpected opportunities to increase the
DWIMity of Perl, should we wish to take them.
- That slot-based parsing techniques deserve more attention
and development.
- That serious programming language research can also be
whimsical, evocative, and emotionally satisfying.
Damian
------------------------------
Date: 21 Sep 2001 12:52:15 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: perl, lvalues, rvalues, and operators
Message-Id: <1001076386.25347@itz.pp.sci.fi>
In article <m3bsk5yyti.fsf@thneed.na.wrq.com>, Michael Slass wrote:
>
>so if the mystery operator is ##, I could do:
>
>$mystring = ($some_constant_string ## s/regex/subst/)
How about this?
($mystring = $some_constant_string) =~ s/regex/subst/;
>Given a subroutine foo() that returns a string, I would like to call
>the routine, mangle the output, and print it in one swell foop:
[snip]
>Instead, I need a temporary variable:
>
>$temp = foo($arg, $notherarg);
>print $temp =~ s/regex/subst;
This won't actually work -- a substitution does not return the
substituted string. This is how you'd write it correctly:
(my $temp = foo($arg, $notherarg)) =~ s/regex/subst/;
print $temp;
If you really want to do it on one line, maybe
print map {(my $temp = $_) =~ s/regex/subst/; $temp} foo($arg, $notherarg);
is more like it? Note that this will apply to substitution to each
value that foo() returns, assuming there is more than one.
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post something,
we discuss its implications. If the discussion happens to answer a question
you've asked, that's incidental." -- nobull in comp.lang.perl.misc
------------------------------
Date: Fri, 21 Sep 2001 14:00:10 +0100
From: "Simon Oliver" <simon.oliver@umist.ac.uk>
Subject: Re: perl, lvalues, rvalues, and operators
Message-Id: <3bab3d37$1@news.umist.ac.uk>
How about susing a second sub?
print re(foo($arg, $notherarg));
sub re {
my $arg = shift;
$arg =~ s/regexp/subst/;
return $arg;
}
--
Simon
------------------------------
Date: 21 Sep 2001 11:12:58 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Pre spawning in perl
Message-Id: <9of7bq$922$1@mamenchi.zrz.TU-Berlin.DE>
According to Mark Jason Dominus <mjd@plover.com>:
> In article <10aq7.6660$OU5.939131@news2-win.server.ntlworld.com>,
> cubol <irl.com@ntlworld.com> wrote:
> >Hi all,
> > I am building a client/server program in perl and would like to
> >pre-spawn, say 10, child process's and hold them in a pool and pass incoming
> >connections to these process's.
>
> You don't want to 'pass' incoming connections; it's better if the
> incomming connections are attached to the child automatically.
>
> I think you will want to follow an outline something like this:
>
>
> use POSIX ":sys_wait_h";
> socket(S, ...);
> bind(S, ...);
> listen(S, ...);
> my $children = 0;
> my $MAX_CHILDREN = 10; # This many children active at once
> my $MAX_SERVICE = 100; # children exit after serving this many clients
>
> while (1) {
> my $dead_child;
>
> if ($children == $MAX_CHILDREN) {
> # Do not continue until at least one child is dead
> wait(); # don't forget to check for error here
> $children--;
> }
>
> # See if any other children are dead
> # continue immediately if none are dead
> do {
> $dead_child = waitpid(-1, &WNOHANG);
> --$children unless $dead_child == -1;
> } until $dead_child == -1;
>
> # Spawn new children
> while ($children < $MAX_CHILDREN) {
> my $pid = fork();
> unless (defined $pid) {
> # couldn't fork; handle this error somehow
> }
> if ($pid == 0) {
> # I am the child
> handle_clients();
> exit;
> }
> # I am the parent
> $children++;
> }
> }
>
> sub handle_clients {
> my $clients_served = 0;
> accept(S, NS); # wait until a conection comes in
> # Now deal with the client; it is connected via NS
> close NS;
> exit if ++$clients_served == $MAX_SERVICE;
> }
>
>
> Here you are letting the child processes inherit the main socket S,
> which was set up by the parent process. The parent never bothers to
> listen for clients; only the children do that. All ten listen at the
> same time. When a client tries to connect, it will be connected to
> one of the idle children.
>
> The parent waits around in the while() loop, managing the children and
> ignoring the network. When a child dies, the parent tries to spawn a
> new one. Most of the time, the parent will be doing wait(), which
> will return only when there is a dead child.
That's very nice. I like the idea of the parent being only concerned
with the well-being of its children. I was never quite sure if
accept() on a single socket was supposed to be called from many
processes in parallel.
> I hope I haven't made any serious errors, and that this is helpful.
Three minor points:
- The parent's wait() could probably be made more robust. For reasons
that are partly due to Perl and partly to the operating system, a
SIGCHLD could get lost, which could mean that not enough children
are re-created. A combination of a periodic non-blocking waitpid
and a check via "kill 0, @kidpids" might help. Yes, that introduces
the problem of PID re-use...
- In handle_clients there seems to be a loop missing around accept()
and ++$clients.
- For purely esthetic reasons, I would let handle_clients merely
return (not exit) after $MAX_SERVICE is exhausted, and let the
child's main program do the exit.
Anno
------------------------------
Date: Fri, 21 Sep 2001 13:30:50 +0100
From: "Alan Fleming" <alan@scotlpuk.com>
Subject: Problem Dieing
Message-Id: <UqGq7.9325$o%6.1482763@news2-win.server.ntlworld.com>
I use the following code in a program which sends out emails. When there is
an error in sending the mail (ie. no mail server on the network) the program
ends, and does not continue, as I expected. However, no error message is
displayed at all. I have managed to get around this problem by manually
creating an if statement, but I'd still like to know why the 'die' statement
doesn't act like it should. Can anyone enlighten me?
sub mail_smtp
{
my($to, $from, $fromname, $subject, $mailtype, $relay, $client,
$scriptversion, @body)=@_;
use Net::SMTP;
my $smtp = Net::SMTP->new($relay);
# Does not work...just ends
# die "Could not open connection: $!" if (! defined $smtp);
# If statement works, but not as nice
if (! defined $smtp)
{
print "Could not open connection: $!<br>\n";
&htmllongfooter;
&exit;
}
else
{
$smtp->mail($from);
$smtp->to($to);
$smtp->data();
$smtp->datasend("To: \"staff\" <$to>\n");
$smtp->datasend("From: \"$fromname\" <$from>\n");
$smtp->datasend("Date: $emailtimedate\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("X-Mailer: $scriptversion\n");
$smtp->datasend("\n");
foreach $line(@body)
{
$line = &removenewline($line);
$line = &unescape($line);
$smtp->datasend("$line\n");
}
$smtp->dataend();
$smtp->quit;
}
}
I use the following system:
Windows 2000 server
IIS 5.0
Perl v5.6.0 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)
Binary build 623 provided by ActiveState Tool Corp.
http://www.ActiveState.com
Built 16:27:07 Dec 15 2000
Thanks in advance...this one has been confusing me for a while.
Alan
www.ScotLPUK.com
------------------------------
Date: Fri, 21 Sep 2001 14:28:11 +0200
From: "JJ" <jocke30_gbg@hotmail.com>
Subject: Re: Problems with $ character
Message-Id: <9ofbnu$6d9$1@vg170.it.volvo.se>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
> $tmp = quotemeta $row[0];
> I dunno, but you can usually convince shells to ignore metacharacters
> by enclosing them in single quotes. I'd try that.
>
> ... $database $table >> '$outfile'";
Both did the trick. I was forced to change a loop before it worked.
> What does that mean?
>
> Note that whatever $SOEORA_SETUP does will go away when the
> system() call is done. The environment changes it makes won't
> be there for subsequent system calls.
>
>
> >How can I solve this and execute it in my Perl script?
I did a UNIX script that does the environment setup and then starts the Perl
script.
Thanks for the help!
BR
Jocke
------------------------------
Date: 21 Sep 2001 04:22:54 -0700
From: phil@snark.freeserve.co.uk (Phil Hibbs)
Subject: Re: Processing page between two other pages.
Message-Id: <979ae699.0109210322.7532e7a4@posting.google.com>
amiwebguy@yahoo.com (Justin) wrote in message news:<19caa707.0109201157.1a91c34d@posting.google.com>...
> I am looking for code to create a processing page between two other
> pages.
You could do it by serving up a partial HTML page and relying on the
browser to render it despite the lack of a </BODY> and </HTML> tag,
and then when the processing is finished, send a <meta
HTTP-EQUIV="Refresh"...> tag that shows the results.
Phil Hibbs.
------------------------------
Date: Fri, 21 Sep 2001 12:10:36 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: regex effeciency question
Message-Id: <od4mqtgnvpk7jg9gv0ti1f4unki3v28aor@4ax.com>
On 21 Sep 2001, rrindels@pd46.com (Rodney Rindels) wrote:
>I am wondering if their is a simpler way to map this protocol
>specification to variables.The '&' (That was used for space padding on
>an existing protocol) must be pulled off of some of the variables
>after we find them in a specific place in the string. The code snippet
>below works but seems very code intensive.
If you have fixed width records, you can use unpack to split the input
into a list. You can then use map to strip off your padding
characters.
#!/usr/bin/perl -w
use strict;
my
$input="\@2001090121225633LOG1928823066102.&62.229.&&4102.&62.229.&56&&&&&6ADBCKE2195&&[DATA]&&&&\@";
my( $start, $year, $month, $day, $data_length, $key, $data )
= map { s/\&//g; $_ }( unpack "AA4A2A2x51A6A10x2A*", $input );
if( $start eq "\@" ){
$data = substr $data, 0, $data_length;
print "$data_length\n";
print "$key\n";
print "$data\n";
print "$month/$day/$year\n";
} else {
print "Protocol Parsing Unsuccessful";
#Code to ask for resend of packet goes here
}
__END__
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: 21 Sep 2001 12:49:01 +0100
From: nobull@mail.com
Subject: Re: regex effeciency question
Message-Id: <u9ofo4bw7m.fsf@wcl-l.bham.ac.uk>
rrindels@pd46.com (Rodney Rindels) writes:
> I am wondering if their is a simpler way to map this protocol
> specification to variables.The '&' (That was used for space padding on
> an existing protocol) must be pulled off of some of the variables
> after we find them in a specific place in the string. The code snippet
> below works but seems very code intensive.
>
> use strict;
> my $input="\@2001090121225633LOG1928823066102.&62.229.&&4102.&62.229.&56&&&&&6ADBCKE2195&&[DATA]&&&&\@";
> my $start=substr($input,0,1);
> if ($start eq "\@"){
>
> my $year=substr($input,1,4);
> $year=~s/(&*?)//g;
> my $month=substr($input,5,2);
> $month=~s/(&*?)//g;
>
> my $day=substr($input,7,2);
> $day=~s/(&*?)//g;
[ and so on ]
I suggest you simply unpack() the string then strip out the & from all
the bits.
Note: s/(&*?)//g is more efficiently written as s/&+//g or better
still as tr/&//d.
my $input="\@2001090121225633LOG1928823066102.&62.229.&&4102.&62.229.&56&&&&&6ADBCKE2195&&[DATA]&&&&\@";
tr/&//d for my ($year,$month,$day,$data_length,$key) = unpack xa4a2a2x51a6a10 => $input;
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 21 Sep 2001 12:45:06 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Regular Expresion help needed
Message-Id: <1001075933.24851@itz.pp.sci.fi>
In article <3baab414.9305270@news.bright.net>, Jonadab the Unsightly One wrote:
>fridden@yahoo.com (Fredrik) wrote:
>
>> The drawback with this expression however is that it doesnt
>> handles nested comments.
>
>Last I checked, neither do most browsers. I could be mistaken,
>but I was under the impression that the following was a single
>valid HTML comment:
><!-- some <!-- text <!-- here -->
Well, it's not technically a *valid* comment. However, any sensible
parser that doesn't simply reject the document as invalid should
interpret it as a single comment.
*This* single comment, of course, is perfectly valid:
<!--> this is <!-- --> a comment <!-->
And so is this:
<!-- some <!-- -- text <!-- -- here -->
Of course, as you said, expecting a browser to parse the first one
correctly is a bit optimistic to say the least...
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post something,
we discuss its implications. If the discussion happens to answer a question
you've asked, that's incidental." -- nobull in comp.lang.perl.misc
------------------------------
Date: Fri, 21 Sep 2001 11:55:41 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: s/// modifies @_ ?
Message-Id: <dfamqt88vh5tb5ccm1pminukohvbo7orrn@4ax.com>
peter pilsl wrote:
>> Wouldn't it be possible to pass (my $match = $1) instead? Or "$1" to
>> generate an anonymous string copy? Or $1 . '', for a similar effect?
>>
>> Somehow, the "passing $1 directly can't be avoided" strikes me as
>> implausible.
>
>I said 'cant be avoided easily', but obviously I was wrong.
>my $match=$1 would not be easy, but $1.'' would be easy or "$1" even
>easier. Any drawbacks on this ?
It looks stupid.
I wonder if this whole thing is not a bug. So you're unsuspectingly
passing $1 and $2 to a sub. That sub unexpectely uses a regex, and
thereby modofies the passed parameters? That most definitely doesn't
sound nice.
But, perhaps a lesson to be drawn from all this: if you use a regex in a
sub, don't use aliases on your parameters. Use copies instead.
sub something_with_a_regex {
my(@param) = @_; # named scalars would be nicer
...
}
--
Bart.
------------------------------
Date: 21 Sep 2001 12:31:01 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Schwartzian Transform problem
Message-Id: <1001075243.24186@itz.pp.sci.fi>
In article <zItq7.21052$386.2995208@news20.bellglobal.com>, Matt Garrish wrote:
>
>What?! However did you come to that conclusion nearly 12 hours after Randal
>posted his message!?! As I mentioned to Randal in an off-group email, I
>quickly replied without stopping to think. So colour me stupid! But now I
>feel better knowing there are bigger dunces out there.
The ways of Usenet propagation are mysterious. There is no guarantee of
same-day delivery for posts to newsgroups.
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post something,
we discuss its implications. If the discussion happens to answer a question
you've asked, that's incidental." -- nobull in comp.lang.perl.misc
------------------------------
Date: 21 Sep 2001 13:00:05 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Schwartzian Transform problem
Message-Id: <9ofdkl$hgm$1@mamenchi.zrz.TU-Berlin.DE>
According to Matt Garrish <matthew.garrish@sympatico.ca>:
>
> "Michael Carman" <mjcarman@home.com> wrote in message
> news:3BA9E727.73B9C8BC@home.com...
> > What?! That's completely wrong.
> >
>
> What?! However did you come to that conclusion nearly 12 hours after Randal
> posted his message!?! As I mentioned to Randal in an off-group email, I
> quickly replied without stopping to think. So colour me stupid! But now I
> feel better knowing there are bigger dunces out there.
Nobody has tried to color you stupid, neither Randal nor Michael. You
posted in error, as it happens on Usenet, and got corrected. Twice, as
it also happens on Usenet. There was no intention to rub it in, if that's
what you are griping about.
> Thanks for making me feel better!
There wasn't much to feel bad about in the first place.
Anno
------------------------------
Date: Fri, 21 Sep 2001 11:51:56 GMT
From: Andrew Cady <please@no.spam>
Subject: Re: search, replace, functions, text wrapping (hard question! I think!)
Message-Id: <87ofo4bw66.fsf@homer.cghm>
ralawrence@my-deja.com (Richard Lawrence) writes:
> Hi all,
>
> I wonder if anyone can help me? I've got some output from a socket
> which I'm converting to HTML on the fly and I'd like it to
> automatically convert url's to hyperlinks.
>
> The problem is that when url's are wrapped, the regexp fails. So I
> tweeked it a little and came up with the following:
>
> $output =~ s#(http://[^\!\"\£\$\^\*\(\)\{\}\[\]\;\:\'\@\,\<\>
> ]+)#make_link($1)#egis;
None of those escapes are necessary, except \]. Actually that
wouldn't be necessary either if you put it right after ^. BTW URLs
should be able to contain '?' (although someone might put an URL at
the end of a question...)
> sub make_link
> {
> my $display = $_[0];
> my $url = $_[0];
> $url =~ s/\n//g;
>
> return "<a href=\"$url\">$display</a>";
> }
>
> Now I know that the regexp for catching URL's isn't perfect, but it
> seems to work for the majority of what I need so I'm not too
> concerned.
>
> However, this is the problem:
>
> The output when it comes to me, is already pre-wrapped and this
> wrapping code automatically inserts two spaces at the beginning of
> each indented line. So you get output that looks like this:
[...]
> Now my regexp utterly breaks because there are two spaces in there
> that have to be taken into consideration.
Yep. Try this one:
s#(http://[$allowed_chars]+(?:\n [$allowed_chars]+)*)#...
Not that hard, but it won't work if the http:// itself is broken over
multiple lines. You won't be able to fix that with a plain regex[1].
I'd recommend reassembling the lines and reformatting after searching
for urls.
[1] actually, you could explicitly allow an optional "\n " after each
char in "http://", i.e. h(\n )?t(\n )?t(\n )?... It still seems to
me like it would be better to reformat the lines.
------------------------------
Date: 21 Sep 2001 05:23:43 -0700
From: sami@xenetic.fi (Samppa)
Subject: String comparison
Message-Id: <30586a1d.0109210423.7c0aaadf@posting.google.com>
hello there,
Here is a simple string comparison code. I wonder why
only step #2 returns match. Does anybody have some ideas.
Code:
-----------------------------------------------------------
#!/usr/bin/perl
$line = 'find or open file something, errno = 2. (43)';
$string1 = 'errno = 2. (43)';
$string2 = 'or open file';
#Step 1
if ($line =~ /$string1/) {
print "Step 1 match\n";
}
#Step 2
if ($line =~ /$string2/) {
print "Step 2 match\n";
}
-----------------------------------------------------------
regards, Sami
------------------------------
Date: Fri, 21 Sep 2001 22:30:56 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: String comparison
Message-Id: <slrn9qmco0.738.mgjv@martien.heliotrope.home>
On 21 Sep 2001 05:23:43 -0700,
Samppa <sami@xenetic.fi> wrote:
> hello there,
>
> Here is a simple string comparison code. I wonder why
> only step #2 returns match. Does anybody have some ideas.
>
> #!/usr/bin/perl
Not that it would have helped you in this case, but
* Always use -w
* Try to use the strict pragma as much as possible, until you know when
and why you shouldn't use it.
They will help you a lot while programming, and they will prevent people
here from nagging about the lack of them.
> $line = 'find or open file something, errno = 2. (43)';
> $string1 = 'errno = 2. (43)';
> $string2 = 'or open file';
>
> #Step 1
> if ($line =~ /$string1/) {
Some (three) of the characters in $string1 are special in regular
expressions. You probably want quotemeta, or the \Q escape sequence.
See the perlre documentation for more information on regular expressions
in general, and \Q in particular, and perlfunc for quotemeta.
Martien
--
Martien Verbruggen |
Interactive Media Division | We are born naked, wet and hungry.
Commercial Dynamics Pty. Ltd. | Then things get worse.
NSW, Australia |
------------------------------
Date: Fri, 21 Sep 2001 13:49:25 +0100
From: "Simon Oliver" <simon.oliver@umist.ac.uk>
Subject: Re: String comparison
Message-Id: <3bab3c5a$1@news.umist.ac.uk>
$string1 works just as if you had typed the text in the regexp.
You should use:
$string1 = 'errno = 2\\. \\(43\\)';
"Samppa" <sami@xenetic.fi> wrote in message
news:30586a1d.0109210423.7c0aaadf@posting.google.com...
> hello there,
>
> Here is a simple string comparison code. I wonder why
> only step #2 returns match. Does anybody have some ideas.
>
> Code:
> -----------------------------------------------------------
> #!/usr/bin/perl
>
> $line = 'find or open file something, errno = 2. (43)';
> $string1 = 'errno = 2. (43)';
> $string2 = 'or open file';
>
> #Step 1
> if ($line =~ /$string1/) {
> print "Step 1 match\n";
> }
>
> #Step 2
>
> if ($line =~ /$string2/) {
> print "Step 2 match\n";
> }
>
> -----------------------------------------------------------
>
> regards, Sami
------------------------------
Date: Fri, 21 Sep 2001 14:56:47 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: String comparison
Message-Id: <04emqt0id2fhlaqim33lr4asm0gba91v4m@4ax.com>
On 21 Sep 2001 05:23:43 -0700, sami@xenetic.fi (Samppa) wrote:
>Here is a simple string comparison code. I wonder why
>only step #2 returns match. Does anybody have some ideas.
[...]
>Code:
[...]
>$line = 'find or open file something, errno = 2. (43)';
>$string1 = 'errno = 2. (43)';
[...]
>if ($line =~ /$string1/) {
You need to escape the brackets in $string1 before you apply it as a
pattern - i.e. "$string1 = 'errno = 2. \(43\)';"
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Fri, 21 Sep 2001 14:05:52 +0100
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: String comparison
Message-Id: <3BAB3B30.A7602EA2@bms.umist.ac.uk>
Samppa wrote:
> Here is a simple string comparison code. I wonder why
> only step #2 returns match. Does anybody have some ideas.
> $line = 'find or open file something, errno = 2. (43)';
> $string1 = 'errno = 2. (43)';
^ ^
The problem is here. When doing the pattern match the pattern looks
like this to perl
if($line1 =~/errno = 2. (43)/){
You need to escape any special characters.
if($line1 =~ /\Q$string1/){
should do it.
HTH
Paul
------------------------------
Date: Fri, 21 Sep 2001 12:02:27 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Use symbol table like 'real' hash
Message-Id: <0qamqtk5k9p50fkdtd5prjvs7qbe77re8f@4ax.com>
Bianka Martinovic wrote:
>If I want to get the value of a certain hash key now, I get it like this:
> $$hash{'value'}
>or if the name of the key is in a var
> $$hash{$val}
>
>Now, if I have passed a symbol table and want to get the value of a symbol
>table entry, I can get it like
> $ { $$hash{$val} }
>If it IS a symbol table. If it is not, this is not defined.
If it is a symbol table, check what ref() returns on a reference to an
entry. Well, an existing entry, anyway. With a symbol table, you should
see "GLOB".
print ref(\$::{_});
--
Bart.
------------------------------
Date: Fri, 21 Sep 2001 11:11:11 +0100
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: using a variable to call a function
Message-Id: <3BAB123F.BEA41728@bms.umist.ac.uk>
Andy wrote:
>
> I am trying to use a variable to make up part or all of a function
> name. I have tried:
> 3 use strict;
this will give you problems.
Can't use string ("bar") as a subroutine ref while "strict refs" in use
at test.pl line 7.
You need to put 'no strict "refs"'; at the begining of your script to
use a string as a subroutine reference.
e.g.
#!perl -w
use strict;
no strict 'refs';
my $func = shift;
foo($func);
sub foo{
my $f = shift;
&$f();
}
sub bar{
print "Here we are!\n";
}
HTH
Paul
------------------------------
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 1786
***************************************