[23090] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5311 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 2 21:05:55 2003

Date: Sat, 2 Aug 2003 18:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 2 Aug 2003     Volume: 10 Number: 5311

Today's topics:
        [regex] Can't get it to be ungreedy <jane.doe@acme.com>
    Re: [regex] Can't get it to be ungreedy <jkeen@concentric.net>
    Re: [regex] Can't get it to be ungreedy <noreply@gunnar.cc>
    Re: [regex] Can't get it to be ungreedy <mgarrish@rogers.com>
    Re: [regex] Can't get it to be ungreedy <abigail@abigail.nl>
    Re: [regex] Can't get it to be ungreedy <jurgenex@hotmail.com>
        Error using Crypt::OpenSSL::RSA - Fails  loading public (John Bergstrom)
        Getting substrings within a String (Tony)
    Re: Getting substrings within a String <jurgenex@hotmail.com>
    Re: Getting substrings within a String <noreply@gunnar.cc>
    Re: how to construct a variable, variable name ? <ddunham@redwood.taos.com>
    Re: Need Perl teacher/school: Network programming <jacqui.caren@ntlworld.com>
        Regex assistance (disco)
    Re: Regex assistance <mgarrish@rogers.com>
    Re: Regex assistance <krahnj@acm.org>
    Re: Regex assistance <jkeen@concentric.net>
    Re: Regex assistance (Tad McClellan)
    Re: Seeking most portable way of accessing serial port (Bbirthisel)
    Re: Some pointers need for a CGI script & Mysql <ron@savage.net.au>
        using Perl5  MD5 module in Perl4? (Kenjis Kaan)
    Re: using Perl5  MD5 module in Perl4? <bart.lateur@pandora.be>
    Re: using Perl5  MD5 module in Perl4? (Tad McClellan)
    Re: Web page with frames... <mgarrish@rogers.com>
    Re: Wide character in print <shtil@comcast.net>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 02 Aug 2003 23:13:47 +0200
From: Jane Doe <jane.doe@acme.com>
Subject: [regex] Can't get it to be ungreedy
Message-Id: <i2aoivovto3d8skk058rnb1s7ov69dodsl@4ax.com>

Hello,

[Since this question is actually a regex used in the open-source
filtering application Privoxy, it's a bit off-topic here, but this is
the closest ng I found about using regex, so please bear with me :-)]

	Although I read the O'Reilly book on regex along with the "The
Filter File" part of the documentation and various links, I can't
figure out why Privoxy searches for patterns in greedy mode, regarless
of my use of either the U switch, or the ? limiter after a counter
like .* or .+ .

Here's the starting HTML, the Privoxy filter, and the output:

1. I just want to remove the complete "Item2" row, as shown :

<html>
<head>
</head>
<body>
	<table>
		<tr>
			<td>
				Item1
			</td>
		</tr>
		<!-- I want to remove this part -->
		<tr>
			<td>
				Item2
			</td>
		</tr>
		<!-- until this point  -->
	</table>
</body>
</html>

2. Here's the Privoxy config I used :

Default Action

{+filter{acme}}
www.acme.com

Filter

FILTER: acme
s|<tr>.+Item2.+</tr>||sigU
# DOESN'T WORK EITHER, SAME RESULT s|<tr>.+?Item2.+?</tr>||sig

3. Here's what Privoxy generates:

<html>
<head>
</head>
<body>
	<table>
		
	</table>
</body>
</html>

=> Ie. the U switch is ignored. Removing the U switch and using the
manual ? ungreedifier doesn't work any better.

Thx much for any tip
JD.


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

Date: 02 Aug 2003 22:35:18 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: [regex] Can't get it to be ungreedy
Message-Id: <bgheb6$36q@dispatch.concentric.net>


"Jane Doe" <jane.doe@acme.com> wrote in message
news:i2aoivovto3d8skk058rnb1s7ov69dodsl@4ax.com...
> Hello,
>
> [Since this question is actually a regex used in the open-source
> filtering application Privoxy, it's a bit off-topic here, but this is
> the closest ng I found about using regex, so please bear with me :-)]
>
> Although I read the O'Reilly book on regex along with the "The
> Filter File" part of the documentation and various links, I can't
> figure out why Privoxy searches for patterns in greedy mode, regarless
> of my use of either the U switch, or the ? limiter after a counter
> like .* or .+ .
>
> Here's the starting HTML, the Privoxy filter, and the output:
>
> 1. I just want to remove the complete "Item2" row, as shown :
>
> <html>
> <head>
> </head>
> <body>
> <table>
> <tr>
> <td>
> Item1
> </td>
> </tr>
> <!-- I want to remove this part -->
> <tr>
> <td>
> Item2
> </td>
> </tr>
> <!-- until this point  -->
> </table>
> </body>
> </html>
>
> 2. Here's the Privoxy config I used :
>
> Default Action
>
> {+filter{acme}}
> www.acme.com
>
> Filter
>
> FILTER: acme
> s|<tr>.+Item2.+</tr>||sigU
> # DOESN'T WORK EITHER, SAME RESULT s|<tr>.+?Item2.+?</tr>||sig
>
> 3. Here's what Privoxy generates:
>
> <html>
> <head>
> </head>
> <body>
> <table>
>
> </table>
> </body>
> </html>
>
> => Ie. the U switch is ignored. Removing the U switch and using the
> manual ? ungreedifier doesn't work any better.
>

Can't comment on what Privoxy should or should not do, but using Perl
regexen you might proceed as follows:
my $str =
'<html>
[etc. up until]
</html>';

# print "$str\n";

if ($str =~ m|.*(<tr>.*Item2.*?<\/tr>)|s) {
 print "To be removed:\n$1\n";
}
print "\n";
if ($str =~ m|^(.*)<tr>.*Item2.*?<\/tr>\n(.*)|s) {
 print "To be kept:\n$1$2\n";
}

Of course, given how complex parsing HTML can become, on this list you would
be more likely to be advised to use a Perl module such as HTML::Parser
rather than using a roll-your-own regex.

Jim Keenan





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

Date: Sun, 03 Aug 2003 00:32:13 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: [regex] Can't get it to be ungreedy
Message-Id: <bghehi$ol0ep$1@ID-184292.news.uni-berlin.de>

Jane Doe wrote:
> # DOESN'T WORK EITHER, SAME RESULT
> s|<tr>.+?Item2.+?</tr>||sig
----------^

The first question mark does not make a difference, if the page 
doesn't include multiple matches of the part of the pattern that 
_follows_ it.

I'd say it works exactly as expected. It matches everything from the 
_first_ occurrence of <tr> until the first occurrence of </tr> after 
the string 'Item2'.

You may want to try:

     s|<tr>\s*<td>\s*Item2.+?</tr>||sig;

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Sat, 02 Aug 2003 23:09:03 GMT
From: "mgarrish" <mgarrish@rogers.com>
Subject: Re: [regex] Can't get it to be ungreedy
Message-Id: <jwXWa.55185$hOa.36544@news02.bloor.is.net.cable.rogers.com>


"James E Keenan" <jkeen@concentric.net> wrote in message
news:bgheb6$36q@dispatch.concentric.net...
>
> if ($str =~ m|.*(<tr>.*Item2.*?<\/tr>)|s) {
>  print "To be removed:\n$1\n";
> }

Which isn't necessarily going to do what he wants (i.e., you're only
checking if Item2 is in the last <tr> in the file). Avoid greedy patterns
unless you absolutely need them.

> print "\n";
> if ($str =~ m|^(.*)<tr>.*Item2.*?<\/tr>\n(.*)|s) {
>  print "To be kept:\n$1$2\n";
> }
>

Adding ^ to the regex is pointless, because .* will start from the beginning
anyway (and escaping slashes just adds noise when you aren't using slashes
as your delimiters). He also used /g on his regex, so you can't assume that
he's only looking to remove one occurrence.

Matt




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

Date: 02 Aug 2003 23:47:08 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: [regex] Can't get it to be ungreedy
Message-Id: <slrnbiojbs.ba.abigail@alexandra.abigail.nl>

Jane Doe (jane.doe@acme.com) wrote on MMMDCXXIII September MCMXCIII in
<URL:news:i2aoivovto3d8skk058rnb1s7ov69dodsl@4ax.com>:
\\  Hello,
\\  
\\  [Since this question is actually a regex used in the open-source
\\  filtering application Privoxy, it's a bit off-topic here, but this is
\\  the closest ng I found about using regex, so please bear with me :-)]
\\  
\\ => Ie. the U switch is ignored. Removing the U switch and using the
\\  manual ? ungreedifier doesn't work any better.


I know it's almost an hour ago I synced with the latest development
version of Perl, but I've never heard of a /U switch with Perl
regexes. Could you explain what has happened the last hour? Didn't
see any message on p5p mentioning a new /U switch.


Oh, I see. You didn't have a Perl question. What makes you think 
this is the right place to ask?



Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
 .qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
 .qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: Sun, 03 Aug 2003 00:03:58 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: [regex] Can't get it to be ungreedy
Message-Id: <OjYWa.5358$td7.184@nwrddc01.gnilink.net>

Jane Doe wrote:

Subject: [regex] Can't get it to be ungreedy

Please see 'perldoc -q greedy':
    "What does it mean that regexes are greedy?  How can I get around it?"

> 1. I just want to remove the complete "Item2" row, as shown :
>
> <html>
> <head>
> </head>
> <body>
> <table>
> <tr>
> <td>
> Item1
> </td>
> </tr>
> <!-- I want to remove this part -->
> <tr>
> <td>
> Item2
> </td>
> </tr>
> <!-- until this point  -->
> </table>
> </body>
> </html>

As has been pointed out many, many times REs are not powerful enough to
parse HTML. You should use an HTML parser for that purpose.

jue




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

Date: 2 Aug 2003 17:21:47 -0700
From: eastmediagroup@yahoo.com (John Bergstrom)
Subject: Error using Crypt::OpenSSL::RSA - Fails  loading public key - Help needed
Message-Id: <5b1e4d6b.0308021621.58832bfa@posting.google.com>

Hello everyone!

I wrote a simple perl program to encrypt a string using
Crypt::OpenSSL::RSA.

Everything as described in the module documentation.   The public key
is a valid X.509 encrypted certificate.

When I tried executing the code I get the following error:
-------------------
Failed to read key at blib/lib/Crypt/OpenSSL/RSA.pm (autosplit into
blib/lib/auto/Crypt/OpenSSL/RSA/load_public_key.al) line 225
-------------------

Below is the exact code I that I'm trying to get working.

Anyone any ideas?

Thanks a lot in advance for your help!

=TEST CODE START=======================
use lib qw(/usr/local/lib/perl5/site_perl/5.6.1/i386-freebsd/);
use lib qw(/usr/local/lib/perl5/site_perl/5.6.1/i386-freebsd/auto/);

  use Crypt::OpenSSL::Random;
  use Crypt::OpenSSL::RSA;

  $key_string ="-----BEGIN CERTIFICATE-----
MIIB8zCCAVygAwIBAgIQC/mb6aRvL5BCaxMVpEBAazANBgkqhkiG9w0BAQQFADAT
MREwDwYDVQQDEwhUZXN0Q2VydDAeFw0wMzA3MTExMjI1NDFaFw0zOTEyMzEyMzU5
NTlaMBMxETAPBgNVBAMTCFRlc3RDZXJ0MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB
iQKBgQDgp5o5a4yQbIv8RHVfJcWmacQmZmzd/GBxhoNOx7H922J48ocGqvgF8beu
PN7wsI/fUqjm5pzFgb12+AyDN5gq0vLMA8wmKS/Cdc+3OCK5EkBE9Xi/RSoeno+Q
o0a0M8lLl8mZBOapyq67FvLsHdQQLcZHqR8kP6Dn54FsTvyfgQIDAQABo0gwRjBE
BgNVHQEEPTA7gBBfYCG1dYRmxJcj+J/jH9YloRUwEzERMA8GA1UEAxMIVGVzdENl
cnSCEAv5m+mkby+QQmsTFaRAQGswDQYJKoZIhvcNAQEEBQADgYEAu9H1SWLTVi4K
mGnsDw/ZeLtd/s8nq+k1b7Ds3LEZMBLaEyMiCkZ8zzEeGmvlJwB54XS+zhwj0RDW
Kc2McRfsUuPkpnGMfANu3zATydGry03FCrO+uid4X91Lf+h9YL+BSewyrsnNjCx0
0qMa+jkZ9C7vcInRRNzabtnypylza7A=
-----END CERTIFICATE-----";

  $plaintext = "Test String";

# not necessary if we have /dev/random:
#  Crypt::OpenSSL::Random::random_seed($good_entropy);

  Crypt::OpenSSL::RSA->import_random_seed();
  $rsa_pub = Crypt::OpenSSL::RSA->new_public_key($key_string);

  $ciphertext = $rsa->encrypt($plaintext);

  print "ENCRYPTED: [$ciphertext]\n";
=TEST CODE END==============


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

Date: 2 Aug 2003 16:45:49 -0700
From: aanter@insight.com (Tony)
Subject: Getting substrings within a String
Message-Id: <2f082a7e.0308021545.3b454b1b@posting.google.com>

Hello All,
    I am very new to Perl and I am trying to pull a substring out of a
larger string as such:

xyxyxyxyxyxyZZxyxyxyxyxyx

I know if I get the index of ZZ in the string can use substr($string,
$index, $len) where len is the number of charcters I want.

I am looking through the Programming Perl book from O'Reilly and I can
not find any easy way to search through the string and get this value.

I have done this several time in java like such and I am trying to the
same thing in Perl:

String str = "xyxyxyxyxyxyZZxyxyxyxyxyx";
int len1 = str.indexOf("ZZ");
String str2 = str.substring(len1, (len1 + "ZZ".length()));

I am sure between something I get here and what I am reading I will
figure this out. Thanks in advance for any help

-Tony


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

Date: Sun, 03 Aug 2003 00:05:25 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Getting substrings within a String
Message-Id: <9lYWa.5360$td7.5028@nwrddc01.gnilink.net>

Tony wrote:
>     I am very new to Perl and I am trying to pull a substring out of a
> larger string as such:
>
> xyxyxyxyxyxyZZxyxyxyxyxyx
>
> I know if I get the index of ZZ in the string can use substr($string,
> $index, $len) where len is the number of charcters I want.
>
> I am looking through the Programming Perl book from O'Reilly and I can
> not find any easy way to search through the string and get this value.

Please see "perldoc -f index"

jue




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

Date: Sun, 03 Aug 2003 02:21:17 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Getting substrings within a String
Message-Id: <bghku8$ok1a7$1@ID-184292.news.uni-berlin.de>

Tony wrote:
> Hello All,
>     I am very new to Perl and I am trying to pull a substring out of a
> larger string as such:
> 
> xyxyxyxyxyxyZZxyxyxyxyxyx
> 
> I know if I get the index of ZZ in the string can use substr($string,
> $index, $len) where len is the number of charcters I want.
> 
> I am looking through the Programming Perl book from O'Reilly and I can
> not find any easy way to search through the string and get this value.
> 
> I have done this several time in java like such and I am trying to the
> same thing in Perl:
> 
> String str = "xyxyxyxyxyxyZZxyxyxyxyxyx";
> int len1 = str.indexOf("ZZ");
> String str2 = str.substring(len1, (len1 + "ZZ".length()));

I fail to understand the point with what you are trying to do. If you 
already know which string you need, why bother with looking up the 
index and then pull out just that string from a larger one??

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Sat, 02 Aug 2003 18:20:50 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: how to construct a variable, variable name ?
Message-Id: <6iTWa.252$4F2.244@newssvr24.news.prodigy.com>

Alex Johnson <alex2100k@yahoo.com> wrote:
> hi, i'm trying to call a variable where the variables name is
> constructed using text and the value of another variable, the kind of
> code that i'm trying to write would be something like this:

>  #!/usr/bin/perl -w

> my $var1 = "three";
> my $total = 1;

> $var2 = '$var' . $total;
> print "$var2";

Regardless of what the above does, you'll probably be happier using a
hash, and constructing the keys.

my %hash;
$hash{"1"} = "three";
my $total = "1";

my $index = $total;
print $hash{$index};

If your contructions will always be integers, you might want to use an
array instead of a hash;

my @array;
$array[1] = "three";
my $total = 1;

my $index = $total;
print $array[$index];

-- 
Darren Dunham                                           ddunham@taos.com
Unix System Administrator                    Taos - The SysAdmin Company
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >


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

Date: Sat, 02 Aug 2003 21:58:51 +0100
From: Jacqui Caren <jacqui.caren@ntlworld.com>
Subject: Re: Need Perl teacher/school: Network programming
Message-Id: <Xns93CBDFA49DD1Djacquicntlworldcom@195.8.68.206>

"Alan J. Flavell" <flavell@mail.cern.ch> wrote in 
news:Pine.LNX.4.53.0307172245100.27244@lxplus076.cern.ch:

> On Thu, Jul 17, nobull@mail.com inscribed on the eternal scroll:
> 
>> > If that's possible at all, I mean other than deliberate co-operation
>> > between the server and the proxy, then it represents a complete
>> > security failure.
> [..]
>> It does not require the co-operation of the server.  It only requires
>> the co-operation of _either_ the client _or_ the server.
> 
> Good point, thanks.
> 
>> So long as the proxy holds a CA private key that's trusted by the
>> client you can get away with it.
> [..]
>> There is no technological solution to the human problem of choosing
>> the who to trust.  If I can trick you into trusting my CA then I can
>> intercept your https traffic.
> 
> Can't argue with that.
> 
> all the best

Sorry for the delay.

I was explaining to someone at work what I like to call the three clases 
of proxy. I will ignore caching...

a proxy
-------
You point your browser at this and it gets pages for you. :-)

often used by companies as part of access control and content
filtering.

very easy to add filters to remove or change content.

Often used to strip javascript and advertising images and links.
- such as dropping all "doubleclick" ads - sorry Tim :-)

I use one to strip "nasty" bits of *script in web pages I do not
want my browser to see. I now strip the macromedia stuff from the
reg because it screws up the current mozilla beta when ran without
flash plugin - the reg has a oad.macormedia.com link instead of
load.macromedia.com link and this causes a tight window open look
in moz.

a reverse proxy
---------------
It appears as the real web site but forwards requests to the real web 
server that does the work.

Often installed within the network of the WSP.

Usually the RP is in the DMZ and the web server is behind a median 
firewall.

used by companies so that DOS attacks that take out the RP does not
impact the backend web server. As a RP is cheap and light
you can very cheaply build a large pool with a much smaller number
of backend web servers.

a virtual reverse proxy
-----------------------
This accepts requests as one (www.foo.com) and forwards them to
a master web site (www.foo.co.uk) for processing.
The result is parsed to ensure links etc do not point to foo.co.uk etc.

Jacqui


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

Date: 2 Aug 2003 13:10:28 -0700
From: jpdiscover@hotmail.com (disco)
Subject: Regex assistance
Message-Id: <9b579c86.0308021210.25f09d7a@posting.google.com>

I am using the readdir comand to read from a directory, but I have
presented the
 contents of my directory below as <DATA> for this presentation so you
can run
 my example.  Surely I missing something simple.  Can someone help?

I want to create a listing meeting the following criteria:
1) The line must start with a letter or number (e.g. no ".", etc.)
2) Only include letters and numbers up until a "." or "_" and disgard
the rest
3) My list can contain duplicates

expected result
===================
goofup
listing
bobby
junk
junk
junk34
bdfds
juice
master1
master2
memory
login
aray
test

----------------- script --------------------

while ( defined ($filename = <DATA>) )
{
    if ($filename !~ /^\.|[#@]/) #Add to array if line does not begin
with "." or contain "#" or "@"
    {
        $filename =~ /(.*?)(\.|\_)(.*?)$/;
        push @dirlist, $1;
    }

}
foreach (@dirlist)
{
    print $_ . "\n";
}


__DATA__ 
 .
 ..
goofup.exe
listing.txt
bobby_switch_db60d
junk_none.log
junk_db4c5A
junk34_stwx_bine33A
bdfds_db4a4A
juice
master1
master2
memory_profile_db
login_profiles
aray_db76eA
test_master1
 .profile
 .cshrc


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

Date: Sat, 02 Aug 2003 21:51:50 GMT
From: "mgarrish" <mgarrish@rogers.com>
Subject: Re: Regex assistance
Message-Id: <WnWWa.54579$hOa.12647@news02.bloor.is.net.cable.rogers.com>


"disco" <jpdiscover@hotmail.com> wrote in message
news:9b579c86.0308021210.25f09d7a@posting.google.com...
>
> I want to create a listing meeting the following criteria:
> 1) The line must start with a letter or number (e.g. no ".", etc.)
> 2) Only include letters and numbers up until a "." or "_" and disgard
> the rest

>     if ($filename !~ /^\.|[#@]/) #Add to array if line does not begin
> with "." or contain "#" or "@"
>     {
>         $filename =~ /(.*?)(\.|\_)(.*?)$/;
>         push @dirlist, $1;
>     }
>

You shouldn't be trying to match in two steps when one will suffice.
Essentially, all you're trying to do is match numbers and letters at the
beginning of a file name, so there's no need to check first if the filename
starts with something other than a letter or number. You can also use a
negative look-ahead assertion to make sure there are no @s or #s in the
string:

if ($filename =~ /^([A-Za-z0-9]+)(?!.*[@#])/ {
   push @dirlist, $1;
}

Matt




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

Date: Sat, 02 Aug 2003 21:53:17 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Regex assistance
Message-Id: <3F2C330E.D4B00114@acm.org>

disco wrote:
> 
> I am using the readdir comand to read from a directory, but I have
> presented the
>  contents of my directory below as <DATA> for this presentation so you
> can run
>  my example.  Surely I missing something simple.  Can someone help?
> 
> I want to create a listing meeting the following criteria:
> 1) The line must start with a letter or number (e.g. no ".", etc.)
> 2) Only include letters and numbers up until a "." or "_" and disgard
> the rest
> 3) My list can contain duplicates
> 
> expected result
> ===================
> goofup
> listing
> bobby
> junk
> junk
> junk34
> bdfds
> juice
> master1
> master2
> memory
> login
> aray
> test
> 
> ----------------- script --------------------
> 
> while ( defined ($filename = <DATA>) )
> {
>     if ($filename !~ /^\.|[#@]/) #Add to array if line does not begin
> with "." or contain "#" or "@"
>     {
>         $filename =~ /(.*?)(\.|\_)(.*?)$/;
>         push @dirlist, $1;
>     }
> 
> }
> foreach (@dirlist)
> {
>     print $_ . "\n";
> }
> 
> __DATA__
> .
> ..
> goofup.exe
> listing.txt
> bobby_switch_db60d
> junk_none.log
> junk_db4c5A
> junk34_stwx_bine33A
> bdfds_db4a4A
> juice
> master1
> master2
> memory_profile_db
> login_profiles
> aray_db76eA
> test_master1
> .profile
> .cshrc


while ( <DATA> ) {
    push @dirlist, /^([a-z0-9]+)/i;
    }

print "$_\n" for @dirlist;



John
-- 
use Perl;
program
fulfillment


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

Date: 02 Aug 2003 22:14:57 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: Regex assistance
Message-Id: <bghd51$36q@dispatch.concentric.net>


"disco" <jpdiscover@hotmail.com> wrote in message
news:9b579c86.0308021210.25f09d7a@posting.google.com...
> I am using the readdir comand to read from a directory, but I have
> [snip]
> I want to create a listing meeting the following criteria:
> 1) The line must start with a letter or number (e.g. no ".", etc.)
What about files beginning with the underscore?
> 2) Only include letters and numbers up until a "." or "_" and disgard
> the rest
> 3) My list can contain duplicates
>
> expected result
> ===================
> goofup
> listing
> bobby
> junk
> junk
> junk34
> bdfds
> juice
> master1
> master2
> memory
> login
> aray
> test
>
> ----------------- script --------------------
>
> while ( defined ($filename = <DATA>) )
> {
>     if ($filename !~ /^\.|[#@]/) #Add to array if line does not begin
> with "." or contain "#" or "@"
>     {
>         $filename =~ /(.*?)(\.|\_)(.*?)$/;
>         push @dirlist, $1;
>     }
>
> }
> foreach (@dirlist)
> {
>     print $_ . "\n";
> }
>
>
> __DATA__
> .
> ..
> goofup.exe
> listing.txt
> bobby_switch_db60d
> junk_none.log
> junk_db4c5A
> junk34_stwx_bine33A
> bdfds_db4a4A
> juice
> master1
> master2
> memory_profile_db
> login_profiles
> aray_db76eA
> test_master1
> .profile
> .cshrc

I found it useful to tackle each step of your logic (including the comment
about @ and #) one step at a time.

my (@dirlist);
while ( <DATA> ) {
    next if (/^[._]/ or /[#@]/);
    # skip right over lines that are obvious non-matches;
    # it will keep the next regex simpler
    chomp;
    if (/^(.+?)[._].*/) {
        push @dirlist, $1;
    } else {
        push @dirlist, $_;
    }
}
print "$_\n" foreach (@dirlist);

I also added several entries to your __DATA__ to reflect all your concerns:

testforlinecontaininghash#sign
testforlinecontainingat@sign
_testforfilebeginningwithunderscore

HTH!

Jim Keenan




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

Date: Sat, 2 Aug 2003 18:29:31 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Regex assistance
Message-Id: <slrnbioiar.1s2.tadmc@magna.augustmail.com>

disco <jpdiscover@hotmail.com> wrote:

> I want to create a listing meeting the following criteria:
> 1) The line must start with a letter or number (e.g. no ".", etc.)
> 2) Only include letters and numbers up until a "." or "_" and disgard
> the rest
> 3) My list can contain duplicates


> while ( defined ($filename = <DATA>) )
> {
>     if ($filename !~ /^\.|[#@]/) #Add to array if line does not begin
> with "." or contain "#" or "@"
>     {
>         $filename =~ /(.*?)(\.|\_)(.*?)$/;
>         push @dirlist, $1;
>     }


You can replace all of that code with this line:

   my @dirlist = map { /^([a-z0-9]+)/i } <DATA>;

or, in your actual application:

   my @dirlist = map { /^([a-z0-9]+)/i } readdir SOMEDIR;


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


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

Date: 02 Aug 2003 19:48:37 GMT
From: bbirthisel@aol.com (Bbirthisel)
Subject: Re: Seeking most portable way of accessing serial port
Message-Id: <20030802154837.13162.00001148@mb-m10.aol.com>

Hi Dave,

>In the interest of saving myself time down the road (as I intend to use the
>utility on several platforms), I am trying to find the most portable way to
>reference the serial port.  While I'm aware that at a lower level on the
>abstraction ladder each OS has its own method of giving access to the serial
>port, I'm hoping that someone has already created a module that provides a
>common interface across a variety of operating system platforms.

Yes, although not all in a single module.

>A search of CPAN turned up several serial port modules, but they all seemed
>to be operating system dependent.  Could it be that's my answer?

The "compatible" set is Win32::SerialPort for Windows and Device::SerialPort
for any of the POSIX compatible OS's including OSX on a Mac. The Device::
version uses POSIX.pm for its abstraction layer. Win32API::CommPort provides
related functionality for Win32::SerialPort.

There is a pre-OSX-for-Mac module which is unrelated.

But the SerialPort family use very similar interfaces and are designed to
handle multi-platform code. There are several examples of cross-platform code
available including old TPJ articles and my (not maintained recently) site at
http://members.aol.com/bbirthisel/alpha.html

-bill


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

Date: Sun, 3 Aug 2003 09:24:17 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: Some pointers need for a CGI script & Mysql
Message-Id: <bghh6o$154q$1@arachne.labyrinth.net.au>

"Gregory Toomey" <NOSPAM@bigpond.com> wrote in message
news:bgfhte$o1b31$1@ID-202028.news.uni-berlin.de...

> "Newbie" <dlaw001@yahoonospam.co.uk> wrote in message
> news:HbHWa.7$Vg.3@newsfep1-gui.server.ntli.net...

I too wrote a web interface to MySQL. It is not just free, but unemcumbered:

http://savage.net.au/Perl-tutorials.html

-- 
Ron Savage
ron@savage.net.au
http://savage.net.au/index.html




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

Date: 2 Aug 2003 12:18:41 -0700
From: tivolinewbie@canada.com (Kenjis Kaan)
Subject: using Perl5  MD5 module in Perl4?
Message-Id: <6a8ba9f8.0308021118.4aa46b19@posting.google.com>

Tivoli's version of Perl is still Perl4.  I am looking for a way that
I can use Perl's modules as found on CPAN inside Perl4?  In particular
I need to use the MD5 module to create unique session ids for a CGI
webapplication.  Unfortunately the constrain is the need to use
Tivoli's perl which is till running on version 4.  But I believe the
MD5 module on CPAN was compiled for Perl5.  Hence the problems.

Any help, hints, pointers appreciated.  TIA


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

Date: Sat, 02 Aug 2003 20:03:10 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: using Perl5  MD5 module in Perl4?
Message-Id: <p66oivc2j8k1oukavqvdhnc1rpd85qq24h@4ax.com>

Kenjis Kaan wrote:

>Tivoli's version of Perl is still Perl4. 

That sounds strange. Perhaps they have two versions of perl, one perl4
and one perl5? You should ask your ISP first.

-- 
	Bart.


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

Date: Sat, 2 Aug 2003 18:37:49 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: using Perl5  MD5 module in Perl4?
Message-Id: <slrnbioiqd.1s2.tadmc@magna.augustmail.com>

Bart Lateur <bart.lateur@pandora.be> wrote:
> Kenjis Kaan wrote:
> 
>>Tivoli's version of Perl is still Perl4. 


Do their PeeCees still run Windows 3.1 too?


> That sounds strange. Perhaps they have two versions of perl, one perl4
> and one perl5? You should ask your ISP first.


Tivoli is not an ISP. It is an IBM.

You were off by 2 letters.  :-)


I heard somewhere over a year ago that they were moving to embedding 
Perl 5 into their apps.

Guess that hasn't happened yet...


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


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

Date: Sat, 02 Aug 2003 19:27:58 GMT
From: "mgarrish" <mgarrish@rogers.com>
Subject: Re: Web page with frames...
Message-Id: <2hUWa.53559$hOa.8079@news02.bloor.is.net.cable.rogers.com>


"Michael Budash" <mbudash@sonic.net> wrote in message
news:mbudash-F2ED8F.22174901082003@typhoon.sonic.net...
>
> nope, must be the tripe all over your face, you ingrate. there goes your
> last chance of EVER getting any useful advice from this group.
>
> *plonk*

God bless newbies...

Matt




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

Date: Sat, 02 Aug 2003 19:01:28 GMT
From: "Yuri Shtil" <shtil@comcast.net>
Subject: Re: Wide character in print
Message-Id: <bUTWa.34008$cF.12752@rwcrnsc53>

What is Eniac 2 ?

Sorry for ignorance !!!

"Gregory Toomey" <NOSPAM@bigpond.com> wrote in message
news:bgd6oa$mt819$1@ID-202028.news.uni-berlin.de...
> "Yuri Shtil" <shtil@comcast.net> wrote in message
> news:a3eWa.21387$cF.8823@rwcrnsc53...
> > Hi all
> >
> > I am getting this when I try to print certain strings. Is it harmless ?
> >
> > If not, how do I get rid of it ?
> >
> > Yuri.
>
> Upgrade! Fixed on Eniac 2.
>
> gtoomey
>
>




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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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


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