[19366] in Perl-Users-Digest
Perl-Users Digest, Issue: 1561 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 18 18:10:33 2001
Date: Sat, 18 Aug 2001 15: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: <998172612-v10-i1561@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 18 Aug 2001 Volume: 10 Number: 1561
Today's topics:
Re: regexp question with no answer yet <lbrtchx@hotmail.com>
Re: Removing all white space from a string (Tad McClellan)
Re: Removing all white space from a string (Tad McClellan)
Re: Removing all white space from a string <godzilla@stomp.stomp.tokyo>
Re: select doesn't detect pipe close <goldbb2@earthlink.net>
Re: select doesn't detect pipe close <uri@sysarch.com>
Re: select doesn't detect pipe close <goldbb2@earthlink.net>
Re: Shouldn't sub foo {} be equivalent to sub foo {retu <iltzu@sci.invalid>
sort alphabetically (greg)
Re: sort alphabetically <davidhilseenews@yahoo.com>
Re: sort alphabetically <shutupsteve@awdang.no.thanks.com>
String Parsing > Remove everything after the first non- (DB)
Re: String Parsing > Remove everything after the first <ilya@martynov.org>
Re: String Parsing > Remove everything after the first <mbudash@sonic.net>
Re: String Parsing > Remove everything after the first <shutupsteve@awdang.no.thanks.com>
Re: String Parsing > Remove everything after the first <davidhilseenews@yahoo.com>
Re: String Parsing > Remove everything after the first <ayamanita.nospam@bigfoot.com>
Re: String Parsing > Remove everything after the first <ayamanita.nospam@bigfoot.com>
Re: This is not a question ... call me slow if you like <iltzu@sci.invalid>
Variable scope surprise in a package.... (Weston Cann)
Re: Variable scope surprise in a package.... <joe+usenet@sunstarsys.com>
Re: Variable scope surprise in a package.... <ilya@martynov.org>
Re: voodoo cookie hash problem <iltzu@sci.invalid>
Weird Formatting Problem <glob@cableone.net>
Re: Weird Formatting Problem (Markus Laire)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 18 Aug 2001 12:01:49 -0400
From: "Albretch" <lbrtchx@hotmail.com>
Subject: Re: regexp question with no answer yet
Message-Id: <998164476.826549@zver>
> Albretch <lbrtchx@hotmail.com> wrote:
> >"Tad McClellan" <tadmc@augustmail.com> wrote in message
> >news:slrn9nqmh0.b9t.tadmc@tadmc26.august.net...
> >> Albretch <lbrtchx@hotmail.com> wrote:
> >> >> If you *have* a maximal length, the solution is trivial: Generate
> >> >> all strings of that or smaller length and apply the regex. Print
> >> >> if match. Now, to do so efficiently...
>
> >> > So my need is not such an "odd" one.
>
>
> Then maybe a search engine might find something? ...
>
>
> What do you plan to use this for?
>
> I can't think of any compelling reasons for wanting to do what
> you want to do. Looks like you have such reasons. Care to share them?
I am working on the design of a data structure that is sort of a
(complicated and huge) linked list for fast searching ... at the end it is
like an indexed text
I want to give people the option to type in regexps as entry queries also
from the web, but the ds does not work well with the FA thinking, therefore
I need the actual strings and I thought this was something easy to get.
> > Can you lead me to pointers regarding this?
>
>
> No, but I can type "convert regular expression" into the little box
> at google.com. :-)
>
> It found (word-wrapped for posting):
>
> "Constructing an Equivalent Regular Grammar from a Regular Expression"
>
> http://www-verimag.imag.fr/~pace/Research/Software/Relic/
> Transformations/RE/toRG.html
>
> and
>
> http://www.csd.uwo.ca/research/grail/.man/
>
> retofl: convert regular expression to finite language
> (if the language of the expression is finite)
Thanks
Took a look at it, but did not find exactly what I need in a first look.
------------------------------
Date: Sat, 18 Aug 2001 10:39:54 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Removing all white space from a string
Message-Id: <slrn9nsvhq.eno.tadmc@tadmc26.august.net>
Philip Newton <pne-news-20010818@newton.digitalspace.net> wrote:
>On Sat, 18 Aug 2001 12:03:21 GMT, "Alan Farrington"
><killspam@redyonder.co.uk> top-posted full-quoted:
>
>> # globally substitute all white space characters with nothing
>> $line =~ s/\s//g;
>
>s/\s+//g should be faster -- then you won't replace every single space
>with nothing but can replace whole stretches of whitespace at a go.
tr///d should be even faster.
-------------------------------------
#!/usr/bin/perl -w
use Benchmark;
timethese 5_000_000, {
control => q( my $str = 'foo bar baz';),
s => q( my $str = 'foo bar baz'; $str =~ s/\s//g),
splus => q( my $str = 'foo bar baz'; $str =~ s/\s+//g),
sstar => q( my $str = 'foo bar baz'; $str =~ s/\s*//g),
tr => q( my $str = 'foo bar baz'; $str =~ tr/ \f\r\n\t//d),
};
-------------------------------------
output (lines trimmed for posting):
Benchmark: timing 5000000 iterations of control, s, splus, sstar, tr...
control: 7 wallclock secs ( 5.57 usr + -0.01 sys = 5.56 CPU) @ 899280.58/s
s: 58 wallclock secs (47.53 usr + 0.06 sys = 47.59 CPU) @ 105064.09/s
splus: 42 wallclock secs (30.60 usr + 0.02 sys = 30.62 CPU) @ 163291.97/s
sstar: 137 wallclock secs (109.89 usr + 0.07 sys = 109.96 CPU) @ 45471.08/s
tr: 15 wallclock secs (13.63 usr + 0.00 sys = 13.63 CPU) @ 366837.86/s
>(But
>what you *shouldn't* do is use s/\s*//g.)
It would appear so :-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 18 Aug 2001 10:48:54 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Removing all white space from a string
Message-Id: <slrn9nt02m.f4o.tadmc@tadmc26.august.net>
Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
>Ilya Martynov wrote:
>
>> What good about Godzilla is that she forced me to study how setup
>> scoring and kill lists in my newsreader :)
>
>I guess I am still in my masochist mood by reading her stuff.
^^^^^^^^^^^^^^^^^
>But now you gave me a point to think about. :-)
Here's another one.
Time spent on our troll's drivel is no longer available for
helping well-meaning folks.
Don't allow her to steal from the other members of the community,
skip reading her posts.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 18 Aug 2001 08:58:56 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Removing all white space from a string
Message-Id: <3B7E90C0.19559E63@stomp.stomp.tokyo>
Tad McClellan aka Ilya Martynov aka Tassilo von Parseval aka Alan Farrington
aka The CLPM Troll aka Ad Nauseam wrote to himself:
> Tassilo von Parseval aka Ilya Martynov aka Tad McClellan aka Alan Farrington
aka The CLPM Troll aka Ad Nauseam wrote to himself:
> >Ilya Martynov aka Tassilo von Parseval aka Tad McClellan aka Alan Farrington
aka The CLPM Troll aka Ad Nauseam wrote to himself:
* Alan Farrington aka Ilya Martynov aka Tassilo von Parseval
aka Tad McClellan aka The CLPM Troll
aka Ad Nauseam wrote a troll article:
> >> What good about Godzilla is that she forced me to study how setup
> >> scoring and kill lists in my newsreader :)
> >I guess I am still in my masochist mood by reading her stuff.
^^^^^^^^^^^^^^^^^
> >But now you gave me a point to think about. :-)
> Here's another one.
> Time spent on our troll's drivel is no longer available for
> helping well-meaning folks.
> Don't allow her to steal from the other members of the community,
> skip reading her posts.
I would think you would become bothered to boredom with
consistently and constantly engaging in dialog with
yourself via your myriad phoney names.
However, you are not noted for being emotionally healthy
nor noted for being mentally healthy.
Godzilla!
------------------------------
Date: Sat, 18 Aug 2001 17:44:43 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: select doesn't detect pipe close
Message-Id: <3B7EE1CB.FD2BF5F8@earthlink.net>
Ben Kennedy wrote:
>
> "Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
> news:3B7CADC8.5459E419@earthlink.net...
> > I have a program which makes a pipe, then forks.
> >
> > The child uses the 4-argument select() on the read end of the pipe
> > to wait until it has work to do. The parent either writes data for
> > the child to process, or else closes the writer.
>
> Make sure you close the read end of the pipe in the parent, and the
> write end in the child as soon after you fork. This will allow the
> child to detect when the pipe actually closes on the parent side
I thought I had been, however, I also notice I've been relying on the
'implicit close' behavior of lexical filehandles when they go out of
scope.
I'll change this to explicit closes and see if the problem goes away.
--
I'm not a programmer but I play one on TV...
------------------------------
Date: Sat, 18 Aug 2001 21:48:46 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: select doesn't detect pipe close
Message-Id: <x7r8u9hwe6.fsf@home.sysarch.com>
>>>>> "BG" == Benjamin Goldberg <goldbb2@earthlink.net> writes:
BG> I thought I had been, however, I also notice I've been relying on the
BG> 'implicit close' behavior of lexical filehandles when they go out of
BG> scope.
BG> I'll change this to explicit closes and see if the problem goes away.
but with forked processes, you never know which will get executed
first. so the other process may run and not detect the close before you
have an implicit close. always close the opposite side of a pipe when
you are done creating it. i learned that lesson hard last year. but now
i have a clean module to fork a process with pipes (much better than
open[23]) and handle its I/O asynchronously..
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: Sat, 18 Aug 2001 18:02:17 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: select doesn't detect pipe close
Message-Id: <3B7EE5E9.C4B364C7@earthlink.net>
Ben Kennedy wrote:
>
> "Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
> news:3B7CADC8.5459E419@earthlink.net...
> > I have a program which makes a pipe, then forks.
> >
> > The child uses the 4-argument select() on the read end of the pipe
> > to wait until it has work to do. The parent either writes data for
> > the child to process, or else closes the writer.
>
> Make sure you close the read end of the pipe in the parent, and the
> write end in the child as soon after you fork. This will allow the
> child to detect when the pipe actually closes on the parent side
Ok: here's my rewritten code:
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
pipe my( $p2cr, $p2cw ) or die "pipe failed: $!";
pipe my( $c2pr, $c2pw ) or die "pipe failed: $!";
defined( my $pid = fork ) or die "fork failed: $!";
select((
select($p2cw), $|=1,
select($c2pw), $|=1,
)[0]);
print STDERR "Forked: $$\n";
if( $pid ) {
# these two lines weren't here, so those two filehandles would
# have been closed implicitly with the return().
local $!;
close $_ for ($p2cr, $c2pw);
return bless { pid => $pid,
reader => $c2pr, writer => $p2cw,
state => "unconnected", }, $class;
} else {
# this was originally:
# @_ = ($p2cr, $c2pw); goto &daemon;
close $_ for ($c2pr, $p2cw);
daemon($p2cr, $c2pw);
die "Shouldn't get here!";
}
}
Here's the daemon code (it hasn't changed any):
sub daemon {
my ($reader, $writer) = @_;
my ($dbi, $sth);
MAIN: while( 1 ) {
vec(my($rflags)="", fileno $reader, 1) = 1;
my $eflags = $rflags;
print STDERR "$$: entering select...\n";
select($rflags, undef, $eflags, undef)
or die "select: $!";
print STDERR "$$: select returned.\n";
if( !vec($rflags, fileno $reader, 1) ) {
print STDERR "$$: EOF seen, exiting\n";
exit;
}
The rest is ommited. Anyway, select() here never returns, ever.
Here's my DESTROY code (it, too, is unchanged):
sub DESTROY {
local $!;
my $self = shift;
return if !keys %$self;
eval{store_fd(["exit"], $$self{writer})};
close $$self{writer} or warn "Couldn't close writer: $!\n";
vec(my($rflags)="", fileno $$self{reader}, 1) = 1;
print STDERR "Waiting for $$self{pid}...\n";
select($rflags, undef, undef, 2) or
warn "DBI::Daemon $$self{pid} won't die, killing it\n";
close $$self{reader};
kill 9, $$self{pid};
waitpid( $$self{pid}, 0 ) && $? && $? != 9 and
warn "DBI::Daemon $$self{pid} died: \$? = $?\n";
%$self = ();
}
This code *always* runs the 'warn ... won't die, killing it' code.
--
I'm not a programmer but I play one on TV...
------------------------------
Date: 18 Aug 2001 21:32:40 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Shouldn't sub foo {} be equivalent to sub foo {return} or sub foo {()} ?
Message-Id: <998168756.18281@itz.pp.sci.fi>
In article <3B773D26.50403@home.com>, Michael Carman wrote:
>Martien Verbruggen wrote:
>
>> An empty sub will actually return @_.
>> I don't know where, if anywhere, this is documented.
>> somehow I must have heard about it in the past, somewhere.
>
>One oddity: this doesn't hold if the sub is called in scalar context:
>
>> Does anyone have a documentation reference for this? Or is it just
>> unspecified behaviour?
>
>As near as I can tell it's unspecified.
What's happening is IMHO a bug: an empty sub gets compiled into a single
"stub" opcode with no "nextstate", and therefore leaves its arguments
lying on the stack for whatever is calling it to deal with.
$ perl -MO=Concise,foo -e 'sub foo {()}'
1w <1> leavesub[t1] K/REFC,1 ->(end)
- <@> lineseq KP ->1w
1u <;> nextstate(main 10 -e:1) v ->1v
1v <0> stub P ->1w
$ perl -MO=Concise,foo -e 'sub foo {}'
1v <1> leavesub[t1] K/REFC,1 ->(end)
1u <0> stub P ->1v
--
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: 18 Aug 2001 11:27:25 -0700
From: benz@op.net (greg)
Subject: sort alphabetically
Message-Id: <9476bc21.0108181027.4fc10431@posting.google.com>
I'm having a hard time trying to find out how to sort alphabetically,
i have two fields, title and text and i'm trying to sort
alphabetically by the title field. Here is my code
open(DATA,"<$data") || print "Error Opening File";
while ($riga = <DATA>)
{
($title,$text) = split(/\|/,$riga);
print "$title";
print "$text"; }
close(DATA);
can somebody please help me?
------------------------------
Date: Sat, 18 Aug 2001 18:45:15 GMT
From: "David Hilsee" <davidhilseenews@yahoo.com>
Subject: Re: sort alphabetically
Message-Id: <%Iyf7.5027$c81.1719111@news1.rdc1.md.home.com>
"greg" <benz@op.net> wrote in message
news:9476bc21.0108181027.4fc10431@posting.google.com...
> I'm having a hard time trying to find out how to sort alphabetically,
> i have two fields, title and text and i'm trying to sort
> alphabetically by the title field. Here is my code
>
> open(DATA,"<$data") || print "Error Opening File";
> while ($riga = <DATA>)
> {
> ($title,$text) = split(/\|/,$riga);
> print "$title";
> print "$text"; }
> close(DATA);
>
> can somebody please help me?
The first way that I thought of:
# read DATA, turning each line into a two-element array
my @arr = map { [ split /\|/ ] } <DATA>;
# sort alphabetically on the first element
@arr = sort { $a->[0] cmp $b->[0] } @arr;
# arr is now is a sorted array of arrays
foreach ( @arr )
{
print "$_->[0] => $_->[1]\n";
}
Or, to combine it all:
foreach ( sort { $a->[0] cmp $b->[0] } map {[split /\|/]} <DATA> )
{
print "$_->[0] => $_->[1]\n";
}
David Hilsee
------------------------------
Date: Sat, 18 Aug 2001 11:52:57 -0700
From: "Stephen Deken" <shutupsteve@awdang.no.thanks.com>
Subject: Re: sort alphabetically
Message-Id: <tnteaun2nd4f0c@corp.supernews.com>
"greg" <benz@op.net> wrote:
> I'm having a hard time trying to find out how to sort
> alphabetically, i have two fields, title and text and
> i'm trying to sort alphabetically by the title field.
Ten million people on this mailing list will tell you to check the FAQ, but
I'm bored, so I'll educate you.
Perl has a built-in sort:
my @sorted = sort @array;
You can optionally specify how to sort with a block of code:
my @sorted = sort { $a cmp $b } @array;
This will sort @array alphabetically, because the { $a cmp $b } part tells
perl to compare $a and $b (which are two elements in the array)
lexographically instead of numerically. In your case, you need to carry
around another bit of information - the rest of the line. So you have to
put it into a hash.
my %hash = ( 'foo' => 'bar',
'bat' => 'baz',
'zip' => 'zop',
);
But hashes don't stay sorted, due to their nature. So you'll have to build
an array of sorted keys, and look up their values later. In this case, you
want the array ('bat', 'foo', 'zip') because that's sorted alphabetically on
the keys of the hash. You can get perl's sort to do this:
my @sorted_keys = sort { $a cmp $b } keys %hash;
This will sort the keys of the hash, and put the sorted array into
@sorted_keys. You can then iterate through it to print them out in order:
foreach (@sorted_keys)
{
print $_ . ' = ' . $hash{$_} . "\n";
}
This will print:
bat = baz
foo = bar
zip = zop
Attached is my solution.
--sjd;
__DATA__
#!/usr/bin/perl -wT
use strict;
my %titles;
my $filename = 'myfile';
open( DATA, $filename ) or die "Error Opening File: $!";
while (<DATA>)
{
chomp;
my ($key,$value) = split( /\|/, $_, 2 );
$titles{$key} = $value;
}
close(DATA);
foreach (sort { $a cmp $b } keys %titles)
{
print $_ . ' = ' . $titles{$_} . "\n";
}
------------------------------
Date: 18 Aug 2001 10:24:51 -0700
From: rubbish_tip@hotmail.com (DB)
Subject: String Parsing > Remove everything after the first non-number
Message-Id: <5e79838e.0108180924.67a8f411@posting.google.com>
Hi,
I need a snippet of a regex to remove everything after the first
non-number in a string. For example, I know that the first few chars
of the string will be numbers - but I don't know how many, or how long
the entire string is. However, I do know that at some point the
numbers will become anything other than numbers - i.e. exclamation
marks, alpha's etc, etc.
For example:
$string="1234567221%sk23$823498as22"
Although there are other numbers after the "%", I'm not interested in
those - just everything up to, but not including the "%".
Hoping someone can assist - thx in advance,
DB
------------------------------
Date: 18 Aug 2001 21:28:35 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: String Parsing > Remove everything after the first non-number
Message-Id: <87vgjlp9a4.fsf@abra.ru>
D> Hi,
D> I need a snippet of a regex to remove everything after the first
D> non-number in a string. For example, I know that the first few chars
D> of the string will be numbers - but I don't know how many, or how long
D> the entire string is. However, I do know that at some point the
D> numbers will become anything other than numbers - i.e. exclamation
D> marks, alpha's etc, etc.
D> For example:
D> $string="1234567221%sk23$823498as22"
$string =~ s/\D.*//;
D> Although there are other numbers after the "%", I'm not interested in
D> those - just everything up to, but not including the "%".
D> Hoping someone can assist - thx in advance,
D> DB
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: Sat, 18 Aug 2001 19:05:42 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: String Parsing > Remove everything after the first non-number
Message-Id: <mbudash-E29073.12055018082001@news.sonic.net>
In article <5e79838e.0108180924.67a8f411@posting.google.com>,
rubbish_tip@hotmail.com (DB) wrote:
> Hi,
>
> I need a snippet of a regex to remove everything after the first
> non-number in a string. For example, I know that the first few chars
> of the string will be numbers - but I don't know how many, or how long
> the entire string is. However, I do know that at some point the
> numbers will become anything other than numbers - i.e. exclamation
> marks, alpha's etc, etc.
>
> For example:
>
> $string="1234567221%sk23$823498as22"
>
> Although there are other numbers after the "%", I'm not interested in
> those - just everything up to, but not including the "%".
>
$string =~ s/%.*$//;
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Sat, 18 Aug 2001 12:18:13 -0700
From: "Stephen Deken" <shutupsteve@awdang.no.thanks.com>
Subject: Re: String Parsing > Remove everything after the first non-number
Message-Id: <tntfqatgfqd645@corp.supernews.com>
rubbish_tip@hotmail.com (DB) wrote:
> ...just everything up to, but not including the "%".
"Michael Budash" <mbudash@sonic.net> wrote:
> $string =~ s/%.*$//;
He meant:
$string =~ s/%.*$/%/;
--sjd;
------------------------------
Date: Sat, 18 Aug 2001 19:31:46 GMT
From: "David Hilsee" <davidhilseenews@yahoo.com>
Subject: Re: String Parsing > Remove everything after the first non-number
Message-Id: <Cozf7.5228$c81.1759461@news1.rdc1.md.home.com>
"Stephen Deken" <shutupsteve@awdang.no.thanks.com> wrote in message
news:tntfqatgfqd645@corp.supernews.com...
> rubbish_tip@hotmail.com (DB) wrote:
> > ...just everything up to, but not including the "%".
>
>
> "Michael Budash" <mbudash@sonic.net> wrote:
> > $string =~ s/%.*$//;
>
> He meant:
>
> $string =~ s/%.*$/%/;
>
> --sjd;
>
Actually, I think both of these are geared toward the example and not
towards the general problem that the OP had.
He said "I need a snippet of a regex to remove everything after the first
non-number in a string.".
David Hilsee
------------------------------
Date: Sat, 18 Aug 2001 20:50:54 GMT
From: Akira Yamanita <ayamanita.nospam@bigfoot.com>
Subject: Re: String Parsing > Remove everything after the first non-number
Message-Id: <3B7ED507.1C48B78F@bigfoot.com>
DB wrote:
>
> I need a snippet of a regex to remove everything after the first
> non-number in a string. For example, I know that the first few chars
> of the string will be numbers - but I don't know how many, or how long
> the entire string is. However, I do know that at some point the
> numbers will become anything other than numbers - i.e. exclamation
> marks, alpha's etc, etc.
>
> For example:
>
> $string="1234567221%sk23$823498as22"
>
> Although there are other numbers after the "%", I'm not interested in
> those - just everything up to, but not including the "%".
Try one of these:
#!/usr/bin/perl
$string="1234567221%sk23$823498as22";
($string)=split(/\D/, $string, 2);
print "$string\n";
$string="1234567221%sk23$823498as22";
$string =~ /(\d+)\D/;
print "$1\n";
$string="1234567221%sk23$823498as22";
$string =~ s/\D.*//;
print "$string\n";
------------------------------
Date: Sat, 18 Aug 2001 21:57:11 GMT
From: Akira Yamanita <ayamanita.nospam@bigfoot.com>
Subject: Re: String Parsing > Remove everything after the first non-number
Message-Id: <3B7EE490.46BD012B@bigfoot.com>
Akira Yamanita wrote:
>
> $string="1234567221%sk23$823498as22";
> $string =~ /(\d+)\D/;
> print "$1\n";
Correction of that:
$string="1234567221%sk23$823498as22";
$string =~ /(\d+)/;
print "$1\n";
They both work but the second is probably better. I don't have it
(nor do I have the other examples) check that the numbers at the
beginning of the string because it was stated by the OP that it
is known that the strings start with numbers.
------------------------------
Date: 18 Aug 2001 20:45:35 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: This is not a question ... call me slow if you like...
Message-Id: <998164032.16642@itz.pp.sci.fi>
[Crossposted to alt.ascii-art. For those reading this there, the blocks
of line noise we're discussing are obfuscated Perl programs.]
In article <3B7B7E29.E1423382@earthlink.net>, Benjamin Goldberg wrote:
>Anno Siegel wrote:
>>
>> We can compress better than that. The banner uses only two characters, so
>> a single bit can tell which. It's less true than yours (I had to unify the
>> line length) but it fits in four lines:
>>
>> use MIME::Base64; $vec = decode_base64( q( vMj5OCHni76DRBEhGkVEFCQkMghfKSK+ry
>> IRQ/hSERF9k4giQh SLiCgog+MQopBDRF8CAAAAAAAAAAAAAAAAAAAAAM93gshx0ncGiIIURFFUgj
>> RA9JXg+4LxlQGebwTRF4xvDBAEJYiiqAQFgOBLTxQ5 6UsDAA==));for($i=0;$i<8*length
>> $vec;$i++) { print "\n" unless $i % 67; print vec( $vec, $i, 1) ? '8' : '_' }
>
>And using just uuencoding works even better, and doesn't require an
>external module:
>
>$u=q{M``````````#@1<['"3E?]!TDB@C1*"*B("&10?A*$?%]%8D8PI>*B.B;1!01
>}. q{MHEA$1$$9'(<0A1PB^A(``````````/!\)X@<)WUG@"A(011%)4@#1%\)OB\8
>}. q{<7QG@^480?<'XQ@!!4((HBDI0``B^]$21D[XT````};$j=unpack("u",$u);
>for(0..938){print vec($j,$_,1)?"8":" ";print"\n"unless(($_+1)%67)}
Clever. Let's see if a fancier font can be made to work:
y/n/\n/,s/\d+/$"x$&/eg,print for qw'n4|9|21|3|n1\2||2|(_-<2_|4_`1|3\3_1\2_|3\3
-_)2_|n\__/\_,_|___/\__|2\__,_|_|1_|\___/\__|_|1_|\___|_|nn4_1\9|3|14|n4__/1-_
)2_|1|5\3_`1|2_|1!1/2-_)2_|n3_|1\___|_|2_|2_|1_|\__,_|\__|_i_\\\___|_|1)n45/n'
Hey, it even fits in three lines.
Actually, the same trick works pretty nicely for any line-style ASCII
art. For example:
#!/usr/bin/perl
y/~/\n/,s/\d+/$"x$&/eg,print for qw#~19/`.4/`.~18f3\\2,f2\\~6Gee1Brain,2|
4\\/-`\\2\\6The1same1thing1we1do~3what1do1you4i.2_\\';.,X1j6every1night,1
Pinky.~5want1to1do4`:_\\1(2\\1\\',-.3Try1to1take1over~10tonight?3.'"`\\1a
\\eY'1)3the1world!2_,.~21`._"\\`-'1`-/12.-;'2|~23/;-`._.-';\\.8,',"4|~21.
'/3"'3|1`\\.-'""-/1/6j~19,/1/9i,-"8(2,/2/~16.-'1.f9.'12`"/2/~15/1,,/ffj\\
6/10.-"`.'-.'~14/1/_\\`--//)5\\1,--._1.-'_,-';1/~13f2".-"-._;'6`._1_.,-i;
1/_;1/~13`.,'3|;1\\10\\`\\_,/-'2\\'~14.'4l1\\1`.8/"\\1_1\\`2j~14f6:1`-'8`
._;."/`-'~14|6`.15,Z2\\~14l7j13.'/1-1\\`.~13.j.2.3<12(.'4.\\1\\f`.1|\\,'~
12,'1`.2\\1/1\\11`|6\\,'||-:j~10.'2.'\\3Y.2\\___......__\\1._3/`.||~2__..
_,-"1.-"'"")2/'1,'1_10\\1|2/"-.`j""``---.._~4.'_.-'"5/1.("-'-"":\\8._)|_(
__.1"'~3;.'9/-'---"".--"'7/,_,^-._1.)~3`:=.__.,itz1`---._.;'11""6""~##;-)
--
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: Sat, 18 Aug 2001 17:04:10 GMT
From: iowa_song88.remove_eights_and_this@hotmail.com (Weston Cann)
Subject: Variable scope surprise in a package....
Message-Id: <iowa_song88.remove_eights_and_this-1808011105080001@240.westvalleycity-01rh15rt-ut.dial-access.att.net>
I'm trying to create an objectish type thing. There's a value that instances
of this object will depend on across the board, so it seemed like a good idea,
rather than making it a property of the object per se, just put it in the
package definition as a file-scope variable. Thus, I have:
package GBView;
my $gbTableName = 'gradebook'; # the constant in question
And for a constructor, something like:
sub new
{
my($pkgName,$dbname,$maskFile) = @_;
my $self = {};
bless $self;
# ... lots of irrelevant stuff omitted...
return $self;
}
And a test routine/method:
sub testGlobal
{
print "\ngbTableName value is: $gbTableName";
}
Nothing too unusual, right? But, much to my surprise, I find that the following
subroutine/method will NOT print out the value of $gbTableName.
Doing:
$a = GBView->new();
$a->testGlobal();
Results in:
gbTableName value is:
So my questions are:
1) Is this right? That is, I couldn't somehow cause this by doing something...
2) If it is right, the behavior is counterintuitive for me... but so far, most
perl behaviors I find counterintuitive have a good reason. Does this?
3) Alternatives? Yeah, I know I can just throw in $self->{'GBTABLENAME'} =
'gradebook' into the constructor, but it doesn't seem quite right....
------------------------------
Date: 18 Aug 2001 13:18:52 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Variable scope surprise in a package....
Message-Id: <m3zo8x1e2r.fsf@mumonkan.sunstarsys.com>
iowa_song88.remove_eights_and_this@hotmail.com (Weston Cann) writes:
> Doing:
>
> $a = GBView->new();
> $a->testGlobal();
>
> Results in:
>
> gbTableName value is:
>
Not for me- it works as expected. As a guess, your file looks
like this
==================================================
$a = GBView->new();
$a->testGlobal();
package GBView;
my $gbTableName = 'gradebook'; # the constant in question
sub new
{
my($pkgName,$dbname,$maskFile) = @_;
my $self = {};
bless $self;
# ... lots of irrelevant stuff omitted...
return $self;
}
sub testGlobal
{
print "\ngbTableName value is: $gbTableName";
}
}
==================================================
which won't work because $gbTableName isn't assigned to
until 3 lines *after* you've printed out it's value.
--
Joe Schaefer "Peace cannot be kept by force. It can only be achieved by
understanding."
--Albert Einstein
------------------------------
Date: 18 Aug 2001 21:19:33 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Variable scope surprise in a package....
Message-Id: <878zghqo9m.fsf@abra.ru>
WC> I'm trying to create an objectish type thing. There's a value that
WC> instances of this object will depend on across the board, so it
WC> seemed like a good idea, rather than making it a property of the
WC> object per se, just put it in the package definition as a
WC> file-scope variable. Thus, I have:
WC> [..skip..]
WC> Doing:
WC> $a = GBView->new();
WC> $a->testGlobal();
WC> Results in:
WC> gbTableName value is:
I can only say that it works for me. Here script I've used:
package GBView;
my $gbTableName = 'gradebook'; # the constant in question
sub new
{
my($pkgName,$dbname,$maskFile) = @_;
my $self = {};
bless $self;
return $self;
}
sub testGlobal
{
print "\ngbTableName value is: $gbTableName";
}
$a = GBView->new();
$a->testGlobal();
It does prints 'gbTableName value is: gradebook'
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: 18 Aug 2001 19:44:22 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: voodoo cookie hash problem
Message-Id: <998163381.16453@itz.pp.sci.fi>
In article <dc31dfbf.0108121246.673a2bb@posting.google.com>, Mongo wrote:
>
>this would print the cookie values to the browser:
>
>foreach $name (keys %cookies) {
> print "\n$name = $cookies{$name}<br>";
>}
>
>but anything i've tried for putting a value in email doesn't work, like:
>
>$cookies{'user'} #for the user value
You still need to give us a simple, *complete* example that demonstrates
the problem. In fact, creating such an example is often enough to find
the bug -- you start with the full program, and remove a part that seems
irrelevant. If the bug is still there, repeat. If the bug vanishes, it
obviously must be in the part you just removed.
That said, I'd guess you have a scoping problem. Probably the %cookies
hash isn't visible inside the subroutine you're sending e-mail in, and
since you haven't turned on warnings or strict mode, perl is assuming
you know what you're doing and not warning about it.
>or even just a more general value like:
>
>$ENV{'HTTP_COOKIE'}<br>
>$ENV{'REMOTE_HOST'}
That's odd. %ENV is global, it should be visible everywhere. Maybe you
have some other problem with the e-mail. Try removing the "$" and see
if the string "ENV{'HTTP_COOKIE'}" appears in the email. If not, you're
obviously not constructing the e-mail properly.
--
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: Sat, 18 Aug 2001 04:00:19 -0700
From: David Aslanian <glob@cableone.net>
Subject: Weird Formatting Problem
Message-Id: <tntb3ecl9bp61f@corp.supernews.com>
Im trying to write a somewhat suppossed to be simple script that:
Uses File::Find to recursivley scan the directorys, and outputs sort of a
"visual" ls, i.e.
+SomeDir
-Somefile
-Somefile2
+SomeDir
-AnotherFile
I can't seem to find a solution on how to be able to tell how much to space
(the tabs), where all the dir/files on one level are at the same spacing
amt, and so on.
I've been trying to do it in "real time", instead of storing all the files
at once and then sorting them out.
I have no idea what to do with this, and nothing I've tried seems to work.
Is their some type of snippet or module I could use here?
David Aslanian
"The majority of our imports come from outside our county."
- Yet another intelligent remark by George W Bush
------------------------------
Date: Sat, 18 Aug 2001 18:27:14 GMT
From: markus.laire@usa.net (Markus Laire)
Subject: Re: Weird Formatting Problem
Message-Id: <Xns9101DA3EFD251markuslairenicfi@192.89.123.233>
David Aslanian <glob@cableone.net> wrote in
<tntb3ecl9bp61f@corp.supernews.com>:
>
>Im trying to write a somewhat suppossed to be simple script that:
>
>Uses File::Find to recursivley scan the directorys, and outputs sort of
>a "visual" ls, i.e.
>
>+SomeDir
> -Somefile
> -Somefile2
> +SomeDir
> -AnotherFile
>
>I can't seem to find a solution on how to be able to tell how much to
>space (the tabs), where all the dir/files on one level are at the same
>spacing amt, and so on.
>
>I've been trying to do it in "real time", instead of storing all the
>files at once and then sorting them out.
>
>I have no idea what to do with this, and nothing I've tried seems to
>work.
>
>Is their some type of snippet or module I could use here?
>
This is short script which uses opendir & readdir to do same thing.
The directory 'e:\\pelit' is main directory whose contents will be printed
This script uses resurcive calls to listdir function. With every call we
pass $indent variable which tells how much to indent lines. I did this fast
but it seems to work.
-------------------- BEGIN SCRIPT --------------------
use strict;
sub listdir($$); # params: dir, indent
listdir('e:\\pelit', 0);
sub listdir($$) {
my ($dir, $indent) = @_;
local *DIR;
opendir DIR, $dir or die "can't opendir $dir: $!";
my @contents = readdir DIR;
closedir DIR;
my $fullpath;
for my $fileOrDir (@contents) {
next if $fileOrDir =~ /^\.{1,2}$/; # ignore '.' and '..'
$fullpath = "$dir\\$fileOrDir";
if (-d $fullpath) { # if directory
print ' ' x $indent . "+ $fileOrDir\n";
listdir $fullpath, $indent + 2;
} else {
print ' ' x $indent . "- $fileOrDir\n";
}
}
}
-------------------- END SCRIPT --------------------
Example listing:
- Tomb Raider 2 backup 20010807.rar
+ Stars!
+ 2-6JRC3
- stars!.GID
- STARS!.HLP
- stars.exe
+ BACKUP
- TUTORIAL.X1
- TUTORIAL.M1
- TUTORIAL.X2
- TUTORIAL.M2
- TUTORIAL.HST
+ NetHack 3.3.1 - Falcon's Eye 1.9.3
- Guidebook.txt
+ config
- jtp_lit1.dat
- jtp_keys.txt
- jtp_opts.txt
- jtp_snds.txt
- jtp_intr.txt
- defaults.nh
+ graphics
- jtp_mou5.pcx
- jtp_mwi4.pcx
- entrance.pcx
... and so on ...
------------------------------
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 1561
***************************************