[28887] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 131 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 12 16:25:02 2007

Date: Mon, 12 Feb 2007 13:24:27 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 12 Feb 2007     Volume: 11 Number: 131

Today's topics:
    Re: Perl in the comics <tzz@lifelogs.com>
    Re: Problem with system command <nospam@nospam.com>
        problems mime::lite <john.swilting@wanadoo.fr>
    Re: problems mime::lite <tadmc@augustmail.com>
    Re: problems mime::lite <jgibson@mail.arc.nasa.gov>
        Qu: REGEXP <averoes@no.no>
    Re: Qu: REGEXP <noreply@gunnar.cc>
    Re: Qu: REGEXP <wahab-mail@gmx.de>
    Re: Qu: REGEXP <averoes@no.no>
    Re: Qu: REGEXP <glennj@ncf.ca>
    Re: read from STDIN <stoupa@practisoft.cz>
    Re: Regex - Unexpected match for /\r/ <joe@inwap.com>
        Regex: Why is overreaching necessary? <Shannon.Jacobs.nospam@gmail.com>
    Re: Regex: Why is overreaching necessary? <jurgenex@hotmail.com>
    Re: Regex: Why is overreaching necessary? <Shannon.Jacobs.nospam@gmail.com>
    Re: Regex: Why is overreaching necessary? <uri@stemsystems.com>
    Re: Regex: Why is overreaching necessary? <someone@example.com>
    Re: Regex: Why is overreaching necessary? <see.sig@rochester.rr.com>
    Re: Regex: Why is overreaching necessary? <Shannon.Jacobs.nospam@gmail.com>
    Re: Regex: Why is overreaching necessary? <joe@inwap.com>
    Re: REGEXP <rvtol+news@isolution.nl>
    Re: split : string containing brackets <m@rtij.nl.invlalid>
    Re: Syntax Error? <Peter@PSDT.com>
    Re: Syntax Error? anno4000@radom.zrz.tu-berlin.de
    Re: What do you think of AxKit? <krotowitz@yahoo.com>
        x-mixed-replace <david@cs.cf.ac.uk>
    Re: x-mixed-replace <spamtrap@dot-app.org>
    Re: x-mixed-replace <david@cs.cf.ac.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 12 Feb 2007 12:27:34 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Perl in the comics
Message-Id: <g69y7n3nv5l.fsf@dhcp-65-162.kendall.corp.akamai.com>

On Fri, 09 Feb 2007 17:04:05 GMT Richard Gration <richard@zync.co.uk> wrote: 

RG> On Fri, 09 Feb 2007 00:57:06 -0800, yuanlii wrote:
>> On Feb 9, 3:05 am, "snappingturtle" <mikosulli...@gmail.com> wrote:
>>> This comic is going up on my cubicle wall:
>>> 
>>> http://www.xkcd.com/c208.html

RG> Worth taking a while to skim the archive ... there are some laugh out loud
RG> ones there ... more so if you have studied maths at a high level.

I only ever studied math at sea level, so it didn't work for me.

Ted


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

Date: Mon, 12 Feb 2007 11:34:16 -0000
From: "Vic Russell" <nospam@nospam.com>
Subject: Re: Problem with system command
Message-Id: <eqpjfn$q06$1$830fa7a5@news.demon.co.uk>

Thanks Ron, I will investigate.

"Ron Bergin" <rkb@i.frys.com> wrote in message 
news:1171041053.803113.220600@s48g2000cws.googlegroups.com...
> On Feb 8, 9:36 am, "Vic Russell" <nos...@nospam.com> wrote:
>> Hi,
>>
>> I am launching an external program as follows (Windows XP OS):-
>>
>> system 'start', 'notepad.exe';
>>
> [snip]
>> simple question is; how do I completely disassociate the system launched
>> application from my program in order to avoid this problem?
>>
>> Regards,
>>
>> Vic
>
> http://search.cpan.org/~jdb/libwin32-0.26/Process/Process.pm
> 




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

Date: Mon, 12 Feb 2007 04:27:25 +0100
From: "john.swilting" <john.swilting@wanadoo.fr>
Subject: problems mime::lite
Message-Id: <45cfde9c$0$27393$ba4acef3@news.orange.fr>

        
a small end of code 
a small end of code contains die
but how to check that the email to pass in parameter is valid  

sub SEND_MAIL{
    my($attachement,$nom,$prenom,$mail,$body) = @_;
    
    my $message_body .= $nom;
    $message_body .= "\n";
    $message_body .= $prenom;
    $message_body .= "\n";
    $message_body .= $body;
    
    my $mime_msg = MIME::Lite->new(
        From => $from_adress,
        To => $mail,
        Subject => 'contact',
        Type => 'TEXT',
        Data => $message_body,
        ) or die "error creating MIME body: $!\n";
    if($attachement eq undef){
        $mime_msg->send;
        }else{
            my $attachement_upload = '/var/www/html/upload/';
            $attachement_upload .= $attachement;
            $mime_msg->attach(
                Type => 'image/gif',
                Path => $attachement_upload,
                Filename => 'attachement.gif'
                ) or die "error attaching image: $!\n";
            $mime_msg->send;        
            }
}


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

Date: Mon, 12 Feb 2007 05:56:56 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: problems mime::lite
Message-Id: <slrnet0lg8.1j8.tadmc@tadmc30.august.net>

john.swilting <john.swilting@wanadoo.fr> wrote:

>     if($attachement eq undef){


That probably does not do what you want.

If you want to test for undef, then:

   if ( ! defined $attachement ) {

If you want to test for empty string then:

   if ( $attachement eq '' )
or
   if ( ! length $attachement )


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


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

Date: Mon, 12 Feb 2007 09:58:30 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: problems mime::lite
Message-Id: <120220070958306108%jgibson@mail.arc.nasa.gov>

In article <45cfde9c$0$27393$ba4acef3@news.orange.fr>, john.swilting
<john.swilting@wanadoo.fr> wrote:

>         
> a small end of code 
> a small end of code contains die
> but how to check that the email to pass in parameter is valid  

perldoc -q address

"How do I check a valid mail address?"

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

Date: Sat, 10 Feb 2007 19:48:43 +0100
From: averroes <averoes@no.no>
Subject: Qu: REGEXP
Message-Id: <45ce13a8$0$455$426a74cc@news.free.fr>

Hi,
i have some problem with a regexp.

i have a string like this ';;;' with no quotes
and i want subtitute it like this ';"";"";'

my code is :

my $string = ';;;' ;
$string =~ s/;;/;"";/g ;
print $string;


but it prints   ;"";;

thank you for your help.

Best regards.


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

Date: Sat, 10 Feb 2007 19:59:49 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Qu: REGEXP
Message-Id: <536j4vF1qve2mU1@mid.individual.net>

averroes wrote:
> i have a string like this ';;;' with no quotes
> and i want subtitute it like this ';"";"";'
> 
> my code is :
> 
> my $string = ';;;' ;
> $string =~ s/;;/;"";/g ;
> print $string;
> 
> but it prints   ;"";;

Try:

     $string =~ s/;(?=;)/;""/g;

Read about extended patterns in "perldoc perlre".

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


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

Date: Sat, 10 Feb 2007 20:05:06 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Qu: REGEXP
Message-Id: <eql6ji$t37$1@mlucom4.urz.uni-halle.de>

averroes wrote:
> i have a string like this ';;;' with no quotes
> and i want subtitute it like this ';"";"";'
> 
> my code is :
> 
> my $string = ';;;' ;
> $string =~ s/;;/;"";/g ;
> print $string;
> but it prints   ;"";;

You're modifying pos($string) in a way that
interferes with the pattern, so it won't
work as intendet. You might use on of the
following:

my $string = ';;;';

1)  $string =~ s/;;/;"";/ while $string =~ /;;/;

2)  $string =~ s/(?<=;)(?=;)/""/g;

3)  $string = join '""', split '', $string;


instead.

Regards

M.


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

Date: Sun, 11 Feb 2007 00:26:44 +0100
From: averroes <averoes@no.no>
Subject: Re: Qu: REGEXP
Message-Id: <45ce54d4$0$1331$426a74cc@news.free.fr>

Gunnar Hjalmarsson a écrit :
> averroes wrote:
>> i have a string like this ';;;' with no quotes
>> and i want subtitute it like this ';"";"";'
>>
>> my code is :
>>
>> my $string = ';;;' ;
>> $string =~ s/;;/;"";/g ;
>> print $string;
>>
>> but it prints   ;"";;
> 
> Try:
> 
>     $string =~ s/;(?=;)/;""/g;
> 
> Read about extended patterns in "perldoc perlre".
> 

Thank you, it's working

And thanks for the advice, i'm reading the extended patterns.

Best regards


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

Date: 12 Feb 2007 15:31:46 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Qu: REGEXP
Message-Id: <slrnet1233.o5h.glennj@smeagol.ncf.ca>

At 2007-02-10 01:48PM, "averroes" wrote:
>  Hi,
>  i have some problem with a regexp.
>  
>  i have a string like this ';;;' with no quotes
>  and i want subtitute it like this ';"";"";'
>  
>  my code is :
>  
>  my $string = ';;;' ;
>  $string =~ s/;;/;"";/g ;
>  print $string;

Why use regular expressions?
     $string = join '""', split //, $string

Unless you haven't shown us your real data.  Is ';;;' the whole string,
or do you have a semi-colon delimited list of fields where some of the
fields are empty?

    $real_string = "field 1;field 2;;;field 5"
    $new_string = join ';', 
                  map {length() ? $_ : '""'} 
                  split /;/, $real_string;

-- 
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry


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

Date: Sat, 10 Feb 2007 00:05:33 +0100
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: read from STDIN
Message-Id: <eqlhls$1bhp$1@ns.felk.cvut.cz>

"Joe Smith" <joe@inwap.com> píše v diskusním příspěvku 
news:hcCdnf70oIJcGlbYnZ2dnUVZ_hadnZ2d@comcast.com...
> Petr Vileta wrote:
>
>> I forgot to mention purpose of my code :-)
>> I try to write script for uploading files with upload progressbar.
>
> First make sure you have the ability to code a progressbar that will
> display properly in a browser.  You'll find it awkward in plain HTML.
>
>   print $HTML_HEADERS;
>   for (1 .. 10) { print "$_ "; sleep 1};
>   print "\n<hr>\n";
>   for (1 .. 10) { print "$_<br>\n"; sleep 1};
>   print $HTML_TRAILERS;
>
I'm able to write working code for MSIE6.x and latter and Firefox  1.0 and 
latter. The trick is to send some "whitespace" to browser.

$|=1; # disable buffering
print $HTML_HEADERS;
for (1 .. 10) { print "$_ " . ' 'x1024; sleep 1};
print "\n<hr>" . ' 'x1024 . "\n";
for (1 .. 10) { print "$_"  . ' 'x1024 . "<br>\n"; sleep 1};
print $HTML_TRAILERS;

But I still need to know why on some server I not get "End of file" from 
STDIN where STDIN is a data stream from browser. Some server setting or Perl 
version is the reason?
For example if I monitor TCP packets I see that browser send 
"Content-Length: 2000" and if I try this

read(STDIN, $buffer, 2048);
&do_something;

Perl never run &do_something because server timeouted this script at read() 
command.
-- 

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail 
from another non-spammer site please.)





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

Date: Sun, 11 Feb 2007 18:16:24 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: Regex - Unexpected match for /\r/
Message-Id: <zbGdnUyZ4cJhUFLYnZ2dnUVZ_hWdnZ2d@comcast.com>

Fred Hare wrote:
> ... is for finding files with \r (= hex '0A' not behind '0D').

   print "Found lone CR in $file\n" if /\r[^\n]/;
   print "Found lone LF in $file\n" if /[^\r]\n/;

	-Joe


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

Date: 10 Feb 2007 17:21:42 -0800
From: "Shannon Jacobs" <Shannon.Jacobs.nospam@gmail.com>
Subject: Regex: Why is overreaching necessary?
Message-Id: <1171156902.147975.247290@h3g2000cwc.googlegroups.com>

Dealing with an array of fixed length strings. Goal is to select based
on certain columns. After rather lengthy study of the camel book and
searching on the web for various examples, I thought this should work:

X @foo2 = grep(/^.{50}(1121|1217|1256|2033).{6}$/,@foo1);

It did not. I consulted with a heavy Perler, and after a few minutes
of wrestling with the problem, he suggested something like this (as I
tinkered it into working):

@foo2 = grep(/^.{50,62}($1121|1217|1256|2033).{6,18}$/,@foo1);

My idea in the broken example was to ignore the first 50 and last 6
characters in each line, which was supposed to leave only the 12
characters in the middle to search against. My fuzzy understanding of
the working version is that I first had to match the entire thing, and
then let Perl fish for candidate matches by truncating down towards
50?

The examples above are slightly simplified for purposes of
explanation. Here is the actual code, just in case I did something
wrong in the tweaking:

@foo2 = grep(/^.{50,62}($form_values{'a_SEARCH_VALUE'}).
{6,18}$/,@foo1);



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

Date: Sun, 11 Feb 2007 02:00:43 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Regex: Why is overreaching necessary?
Message-Id: <fNuzh.1622$2%1.70@trndny02>

Shannon Jacobs wrote:
> Dealing with an array of fixed length strings. Goal is to select based
> on certain columns. After rather lengthy study of the camel book and
> searching on the web for various examples, I thought this should work:
>
> X @foo2 = grep(/^.{50}(1121|1217|1256|2033).{6}$/,@foo1);
>
> It did not. I consulted with a heavy Perler, and after a few minutes
> of wrestling with the problem, he suggested something like this (as I
> tinkered it into working):
>
> @foo2 = grep(/^.{50,62}($1121|1217|1256|2033).{6,18}$/,@foo1);

Ouch! That hurts!
When dealing with fixed length formats then REs are certainly not the tool 
of choice.
One much better alternative: substr()
The other commonly used alternative: pack()/unpack()

jue 




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

Date: 10 Feb 2007 18:13:44 -0800
From: "Shannon Jacobs" <Shannon.Jacobs.nospam@gmail.com>
Subject: Re: Regex: Why is overreaching necessary?
Message-Id: <1171160024.431083.13840@v33g2000cwv.googlegroups.com>

On Feb 11, 11:00 am, "J=FCrgen Exner" <jurge...@hotmail.com> wrote:
> Shannon Jacobs wrote:
> > Dealing with an array of fixed length strings. Goal is to select based
> > on certain columns. After rather lengthy study of the camel book and
> > searching on the web for various examples, I thought this should work:
>
> > X @foo2 =3D grep(/^.{50}(1121|1217|1256|2033).{6}$/,@foo1);
>
> > It did not. I consulted with a heavy Perler, and after a few minutes
> > of wrestling with the problem, he suggested something like this (as I
> > tinkered it into working):
>
> > @foo2 =3D grep(/^.{50,62}($1121|1217|1256|2033).{6,18}$/,@foo1);
>
> Ouch! That hurts!
> When dealing with fixed length formats then REs are certainly not the tool
> of choice.
> One much better alternative: substr()
> The other commonly used alternative: pack()/unpack()

It was not my intention to cause you any pain, but that's not the
question I asked, though I suppose it's good to rethink problems in
terms of the objectives. Actually, in another part of the program I do
use substrings to massage things where a more linear approach seemed
more suitable. I vaguely remember considering unpack() long ago (the
code has evolved over a period of about 10 years), but decided against
it for some reason. I didn't need pack() since this is actually a
backend query program, and there are limitations in the programs that
are exporting the data. (And yes, the Perler with whom I discussed the
problem did suggest alternatives including substrings.)

I'd still like to understand why this regular expression works as it
does. Or perhaps you should clarify your intended sense of "painful"?
As it is, I'm content with how well the code works. It seems like an
adequate amount of search bang for the small regex buck.



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

Date: Sat, 10 Feb 2007 22:20:50 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Regex: Why is overreaching necessary?
Message-Id: <x7hctt1ist.fsf@mail.sysarch.com>

>>>>> "SJ" == Shannon Jacobs <Shannon.Jacobs.nospam@gmail.com> writes:

  SJ> Dealing with an array of fixed length strings. Goal is to select based
  SJ> on certain columns. After rather lengthy study of the camel book and
  SJ> searching on the web for various examples, I thought this should work:

  SJ> X @foo2 = grep(/^.{50}(1121|1217|1256|2033).{6}$/,@foo1);

  SJ> It did not. I consulted with a heavy Perler, and after a few minutes
  SJ> of wrestling with the problem, he suggested something like this (as I
  SJ> tinkered it into working):

  SJ> @foo2 = grep(/^.{50,62}($1121|1217|1256|2033).{6,18}$/,@foo1);

you should show some sample data as well so we can see what you are
matching. as jurgen said that is painful to read. even good perl hackers
will have trouble deciphering it quickly and that means it is not good
perl IMO.

also this line has $1121 and the previous one didn't have the $ so i am
not sure which is correct.


  SJ> My idea in the broken example was to ignore the first 50 and last 6
  SJ> characters in each line, which was supposed to leave only the 12
  SJ> characters in the middle to search against. My fuzzy understanding of
  SJ> the working version is that I first had to match the entire thing, and
  SJ> then let Perl fish for candidate matches by truncating down towards
  SJ> 50?

no need to ignore the last 6 chars as that won't affect the match unless
some lines were of different lengths.


  SJ> The examples above are slightly simplified for purposes of
  SJ> explanation. Here is the actual code, just in case I did something
  SJ> wrong in the tweaking:

  SJ> @foo2 = grep(/^.{50,62}($form_values{'a_SEARCH_VALUE'}).
  SJ> {6,18}$/,@foo1);

that doesn't seem to be a fixed offset value. the initial skip is from
50-62 chars. if the search value can't appear in that, why not just
grep for that? is the search value something with alternation as the
above lines suggest? then a faster thing might be to grab the part you
want and look it up in a hash of wanted values. alternation can be very
slow especially with many choices (due to backtracking).

in fact as you have been told, substr and a hash lookup might be the
perfect thing for this (but i am not sure since the leading skip can
vary in size). again, showing some real data would help as we could see
what variants there are, what the searched for parts look like (and if
they are not found earlier in the string), etc. 

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Sun, 11 Feb 2007 04:08:11 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Regex: Why is overreaching necessary?
Message-Id: <LEwzh.47815$Fd.6787@edtnps90>

Shannon Jacobs wrote:
> Dealing with an array of fixed length strings. Goal is to select based
> on certain columns. After rather lengthy study of the camel book and
> searching on the web for various examples, I thought this should work:
> 
> X @foo2 = grep(/^.{50}(1121|1217|1256|2033).{6}$/,@foo1);
> 
> It did not. I consulted with a heavy Perler, and after a few minutes
> of wrestling with the problem, he suggested something like this (as I
> tinkered it into working):
> 
> @foo2 = grep(/^.{50,62}($1121|1217|1256|2033).{6,18}$/,@foo1);
> 
> My idea in the broken example was to ignore the first 50 and last 6
> characters in each line,

@foo2 = grep substr( $_, 50, -6 ) =~ /1121|1217|1256|2033/, @foo1;

> which was supposed to leave only the 12
> characters in the middle to search against.

@foo2 = grep substr( $_, 50, 12 ) =~ /1121|1217|1256|2033/, @foo1;




John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


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

Date: Sat, 10 Feb 2007 23:08:35 -0500
From: Bob Walton <see.sig@rochester.rr.com>
Subject: Re: Regex: Why is overreaching necessary?
Message-Id: <45ce96c3$0$5790$4c368faf@roadrunner.com>

Shannon Jacobs wrote:
> Dealing with an array of fixed length strings. Goal is to select based
> on certain columns. After rather lengthy study of the camel book and
> searching on the web for various examples, I thought this should work:
> 
> X @foo2 = grep(/^.{50}(1121|1217|1256|2033).{6}$/,@foo1);
> 
> It did not. I consulted with a heavy Perler, and after a few minutes
> of wrestling with the problem, he suggested something like this (as I
> tinkered it into working):
> 
> @foo2 = grep(/^.{50,62}($1121|1217|1256|2033).{6,18}$/,@foo1);
--------------------------^
I assume this $ is a typo and should be omitted.

> 
> My idea in the broken example was to ignore the first 50 and last 6
> characters in each line, which was supposed to leave only the 12
> characters in the middle to search against. My fuzzy understanding of
> the working version is that I first had to match the entire thing, and
> then let Perl fish for candidate matches by truncating down towards
> 50?

It is generally courteous to provide some sample data against which your 
regex should match (or not match, as the case may be).  I gather you 
have data in records which are 68 characters long, and that somewhere 
between the 51st and 62nd character there may or may not be some 
specific four-character numeric strings.  The regex as modified will 
match from 50 to 62 of any characters, followed by either of four 
specific 4-character numbers, followed by 6 to 18 of any character, 
followed by the end of the record.  In addition, the regex has the side 
effect of assigning variable $1 to the 4-digit string that was actually 
matched (assuming a match occurred).  But your code throws that away 
(which is fine if that is what you want).

When dealing with fixed-length strings, substr() is your friend. 
Something like:

use strict;
use warnings;
use Data::Dumper;
my(@foo1,@foo2);
while(<DATA>){
   chomp;
   push @foo1,$_;
}
@foo2=grep(substr($_,50,12)=~/1121|1217|1256|2033/,@foo1);
print Dumper(\@foo2);
__END__
          11111111112222222222333333333344444444445555555555666666666
12345678901234567890123456789012345678901234567890123456789012345678
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx112100000000xxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx000000001217xxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx001121000000xxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx000011210000xxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx000000012560xxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0000000000002033xx

would work.  Note how I provided a working example anyone can 
copy/paste/run, complete with sample data, as suggested in the posting 
guidelines for this newsgroup.
> 
> The examples above are slightly simplified for purposes of
> explanation. Here is the actual code, just in case I did something
> wrong in the tweaking:
> 
> @foo2 = grep(/^.{50,62}($form_values{'a_SEARCH_VALUE'}).
> {6,18}$/,@foo1);
> 
-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl


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

Date: 11 Feb 2007 17:15:11 -0800
From: "Shannon Jacobs" <Shannon.Jacobs.nospam@gmail.com>
Subject: Re: Regex: Why is overreaching necessary?
Message-Id: <1171242911.047977.38260@a34g2000cwb.googlegroups.com>

> > @foo2 = grep(/^.{50,62}($1121|1217|1256|2033).{6,18}$/,@foo1);

Yes, the first $ there was a typo left over from the actual code
sample that was included later in the OP (where that part of the
search target was stored in a variable). My apologies for not
including a sample of the data, but I had attempted to constrain the
question in a way that I hoped limited the need for reference to the
actual data. Here is a short sample from the file:

Irrational Numbers                      1976770514 392   0   0SF

Maske:  Thaery                          1976770514 393   0   0SF

The Turning Place                       1976770515 394   0   0SF

The October Circle                      1975770516 395   0   0Fi

Our Invaded Universities                1974830410 671        EdPSHi
Space Mail                              1980840607   8 564 565SF

There are spaces at the ends of the apparently short lines, so all of
them are actually of the same length. The embedded 0s are actually an
anachronism of the source programs, but they 'seem' harmless, so I've
always ignored them. I think it's irrelvant, but for the sake of
sizing, this data file is only around 200 Kb in total.

Since substring operations have come up again, let me clarify that in
this part of the program it seemed easier and better to use a simple
regex at each stage of refinement. I didn't want to break the lines
apart and just put them together again (though later on I did break
the final filtered results apart for output). (In addition, I know
that the current approach allows me to usefully input search targets
consisting of regular expressions, such as ^.{44}07 to pull the
current year's entries.)

At this point I am most interested in the operation and probable
performance advantages of John Krahn's

@foo2 = grep substr( $_, 50, 12 ) =~ /1121|1217|1256|2033/, @foo1;

versus my (corrected) version of

@foo2 = grep(/^.{50,62}(1121|1217|1256|2033).{6,18}$/,@foo1);

 . I have the (fuzzy) intuition that his code is more directly
performing the operation that I described in the OP. If so, I'd like
to share it with the Perler who led me to my probably awkward solution
(but I'm not sure yet which is better nor why).

I am also still interested in understanding why this version failed:

@foo2 = grep(/^.{50}(1121|1217|1256|2033).{6}$/,@foo1);

Minor point is wondering whether or not it is necessary to worry about
the end of the string (as mentioned by Uri Guttman). It seems to me
that there would still be a general risk of false positives in the
tail of the string unless they are explicitly ignored. Or is he really
saying that my version is still subject to that risk?

On Feb 11, 1:08 pm, Bob Walton <see....@rochester.rr.com> wrote:
> Shannon Jacobs wrote:
> > Dealing with an array of fixed length strings. Goal is to select based
> > on certain columns. After rather lengthy study of the camel book and
> > searching on the web for various examples, I thought this should work:
>
> > X @foo2 = grep(/^.{50}(1121|1217|1256|2033).{6}$/,@foo1);
>
> > It did not. I consulted with a heavy Perler, and after a few minutes
> > of wrestling with the problem, he suggested something like this (as I
> > tinkered it into working):
>
> > @foo2 = grep(/^.{50,62}($1121|1217|1256|2033).{6,18}$/,@foo1);
>
> --------------------------^
> I assume this $ is a typo and should be omitted.
>
>
>
> > My idea in the broken example was to ignore the first 50 and last 6
> > characters in each line, which was supposed to leave only the 12
> > characters in the middle to search against. My fuzzy understanding of
> > the working version is that I first had to match the entire thing, and
> > then let Perl fish for candidate matches by truncating down towards
> > 50?
>
> It is generally courteous to provide some sample data against which your
> regex should match (or not match, as the case may be).  I gather you
> have data in records which are 68 characters long, and that somewhere
> between the 51st and 62nd character there may or may not be some
> specific four-character numeric strings.  The regex as modified will
> match from 50 to 62 of any characters, followed by either of four
> specific 4-character numbers, followed by 6 to 18 of any character,
> followed by the end of the record.  In addition, the regex has the side
> effect of assigning variable $1 to the 4-digit string that was actually
> matched (assuming a match occurred).  But your code throws that away
> (which is fine if that is what you want).
>
> When dealing with fixed-length strings, substr() is your friend.
> Something like:
>
> use strict;
> use warnings;
> use Data::Dumper;
> my(@foo1,@foo2);
> while(<DATA>){
>    chomp;
>    push @foo1,$_;}
>
> @foo2=grep(substr($_,50,12)=~/1121|1217|1256|2033/,@foo1);
> print Dumper(\@foo2);
> __END__
>           11111111112222222222333333333344444444445555555555666666666
> 12345678901234567890123456789012345678901234567890123456789012345678
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx112100000000xxxxxx
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx000000001217xxxxxx
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx001121000000xxxxxx
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx000011210000xxxxxx
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx000000012560xxxxxx
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0000000000002033xx
>
> would work.  Note how I provided a working example anyone can
> copy/paste/run, complete with sample data, as suggested in the posting
> guidelines for this newsgroup.
>
> > The examples above are slightly simplified for purposes of
> > explanation. Here is the actual code, just in case I did something
> > wrong in the tweaking:
>
> > @foo2 = grep(/^.{50,62}($form_values{'a_SEARCH_VALUE'}).
> > {6,18}$/,@foo1);
>
> --
> Bob Walton
> Email:http://bwalton.com/cgi-bin/emailbob.pl



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

Date: Sun, 11 Feb 2007 17:59:05 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: Regex: Why is overreaching necessary?
Message-Id: <ecCdncNB6fRzVFLYnZ2dnUVZ_tGsnZ2d@comcast.com>

Shannon Jacobs wrote:

> @foo2 = grep(/^.{50,62}(1121|1217|1256|2033).{6,18}$/,@foo1);

If all of your input strings are 50+4+18 = 72 = 62+4+6 characters long,
then forcing the tail end to be 6 to 18 characters long is redundant.
Once the pattern has skipped 50 to 60 characters of the 72-character
string and match 4 characters, the remainder will always be 6 to 18 characters.

> . I have the (fuzzy) intuition that his code is more directly
> performing the operation that I described in the OP. If so, I'd like
> to share it with the Perler who led me to my probably awkward solution
> (but I'm not sure yet which is better nor why).
> 
> I am also still interested in understanding why this version failed:
> 
> @foo2 = grep(/^.{50}(1121|1217|1256|2033).{6}$/,@foo1);

If your input is 72 characters long, that will never match.
You will have 18 characters at the end, not 6.

> Minor point is wondering whether or not it is necessary to worry about
> the end of the string (as mentioned by Uri Guttman). It seems to me
> that there would still be a general risk of false positives in the
> tail of the string unless they are explicitly ignored. Or is he really
> saying that my version is still subject to that risk?

If all your input is fixed-length strings, there will never be
false positives.  Are you planning on rejecting all lines that are
not exactly 72 characters long?

	-Joe


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

Date: Sun, 11 Feb 2007 01:15:11 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: REGEXP
Message-Id: <eqlqrs.r8.1@news.isolution.nl>

averroes schreef:

> i have some problem with a regexp.
>
> i have a string like this ';;;' with no quotes
> and i want subtitute it like this ';"";"";'
>
> my code is :
>
> my $string = ';;;' ;
> $string =~ s/;;/;"";/g ;
> print $string;
>
>
> but it prints   ;"";;
>
> thank you for your help.
>
> Best regards.

You also posted this in news:alt.comp.lang.perl.

You shouldn't multi-post.

Use cross-posting, with the followup set to one of the groups, or even
better: try one group, and only if that doesn't work out, try another.

-- 
Affijn, Ruud

"Gewoon is een tijger."



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

Date: Mon, 12 Feb 2007 09:02:28 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: split : string containing brackets
Message-Id: <khj5a4-0v6.ln1@news.rtij.nl>

On Thu, 08 Feb 2007 17:05:26 +0000, anno4000 wrote:

> attn.steven.kuo@gmail.com <attn.steven.kuo@gmail.com> wrote in
> comp.lang.perl.misc:
>> On Feb 8, 6:53 am, "Prototype" <goo...@pmburton.clara.co.uk> wrote:
> 
> [...]
> 
>> If your "grammer" is really complicated, then you may want to look at
>> parser generators on CPAN:
>> 
>> 
>> Parse::Yapp
>> or
>> Parse::RecDescent
> 
> The latter is even a core module.

I just discovered this independently and it's awfully cool. It's not yet
another recursive decent parser generator, but actually has all the
features I fantasized over the years that a recursive decent parser
generator should have. And then some.

M4


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

Date: Sat, 10 Feb 2007 12:46:52 GMT
From: Peter Scott <Peter@PSDT.com>
Subject: Re: Syntax Error?
Message-Id: <pan.2007.02.10.12.46.48.937120@PSDT.com>

On Fri, 09 Feb 2007 18:10:18 +0000, Ilya Zakharevich wrote:
> <anno4000@radom.zrz.tu-berlin.de>], who wrote in article <533c8eF1qht84U1@mid.dfncis.de>:
>> I doubt that TomC posted that code.  "system" cannot be followed
>> by a block, that's a syntax error by itself.
> 
> Of course it can.
> 
> P.S.  perl -wle 'system {"/bin/echo"} qw(foo bar)'

Hmmm,

$ perl -wle 'system {"/bin/echo"} qw(foo bar)'
bar

$ perl -MO=Deparse -wle 'system {"/bin/echo"} qw(foo bar)'
BEGIN { $^W = 1; }
BEGIN { $/ = "\n"; $\ = "\n"; }
system do {
    '/bin/echo'
}, 'foo', 'bar';
-e syntax OK

$ perl -wle 'system do {"/bin/echo"}, qw(foo bar)'
foo bar

Urp.

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/



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

Date: 10 Feb 2007 13:52:41 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Syntax Error?
Message-Id: <536119F1q3kamU1@mid.dfncis.de>

Ilya Zakharevich  <nospam-abuse@ilyaz.org> wrote in comp.lang.perl.misc:
> [A complimentary Cc of this posting was sent to
> 
> <anno4000@radom.zrz.tu-berlin.de>], who wrote in article
> <533c8eF1qht84U1@mid.dfncis.de>:
> > I doubt that TomC posted that code.  "system" cannot be followed
> > by a block, that's a syntax error by itself.
> 
> Of course it can.

[...]
 
> P.S.  perl -wle 'system {"/bin/echo"} qw(foo bar)'

Oh well... indirect object syntax.  Does that even count?  :)

Anno


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

Date: Mon, 12 Feb 2007 09:07:42 +0100
From: "Marco Neumann" <krotowitz@yahoo.com>
Subject: Re: What do you think of AxKit?
Message-Id: <eqp6pg$js0$1@news.uni-kl.de>

Hi, J!

"J. Gleixner" <glex_no-spam@qwest-spam-no.invalid> schrieb im Newsbeitrag
news:45cca9c2$0$507$815e3792@news.qwest.net...
> The AxKit mailing list would probably give you
> more information:
>
> http://axkit.org/mailinglist.xml

Thanks for the tip. From the archive of the mailing list I can see that
AxKit is not only still under development but a whole new version was
released only a few months ago.

I am still not clear though, on why there is so little attention to this
project. Perhaps AxKit is ok and the reason is that there are so many other
ways to do it in perl...

And so many ways without XSLT, perhaps the Template Toolkit is too good...

Cheers,
Marco.




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

Date: Sun, 11 Feb 2007 20:53:19 GMT
From: "David Walker" <david@cs.cf.ac.uk>
Subject: x-mixed-replace
Message-Id: <3nLzh.5838$tz6.2043@newsfe2-gui.ntli.net>

Hi,

I am trying to upload a file to a web server, process it with a Perl script 
and then return the following to the client:
    1) A summary of the processing
    2) a gzipped tar file of the processed data.

I had thought that the following should work:

print "Content-type: multipart/x-mixed-replace;boundary=frontier\n";
print "\n--frontier\n";
print "Content-type: text/html\n\n";
print "<HTML><BODY>Here is the summary!</BODY></HTML>";
print "\n--frontier\n";
print "Content-Type: application/x-tgz; name=$archive\n";
print "Content-Transfer-Encoding: base64\n";
print "Content-Disposition: inline; filename=$archive\n\n";
$gz = gzopen(\*STDOUT, "wb") or die "Cannot open stdout: $gzerrno\n" ;
$gz->gzwrite($bigbuf);
$gz->gzclose;
print "\n--frontier--\n";

But the above produces the HTML page with the gzipped tar file added on to 
the end. What I want to happen is for the HTML page to be displayed, and 
then the gzipped tar file to be intercepted by the browser to be saved. If I 
miss out the first 5 lines, and the last line, of the above code then I get 
the gzipped tar file OK and can save it, so that part works OK by itself.. 
Perhaps I have simply misunderstood what x-mixed-replace is supposed to do. 
Any help would be appreciated.

Regards
David




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

Date: Sun, 11 Feb 2007 16:21:44 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: x-mixed-replace
Message-Id: <m264a8e6fr.fsf@local.wv-www.com>

"David Walker" <david@cs.cf.ac.uk> writes:

> Perhaps I have simply misunderstood what x-mixed-replace is supposed to do. 
> Any help would be appreciated.

The same thing it's supposed to do if it's printed by Python, Ruby, or some
other language. Your question has nothing to do with Perl, it has to do with
HTTP and MIME, and more specifically, with one particular browser's support
for server push.

At any rate, the answer is simple, I'm afraid - IE, at least up to and
including IE 6, does not support server push with x-mixed-replace. Given
the number of IE6 users still out there, that probably means you'll need
to find another solution. :-(

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Sun, 11 Feb 2007 21:57:58 GMT
From: "David Walker" <david@cs.cf.ac.uk>
Subject: Re: x-mixed-replace
Message-Id: <GjMzh.5846$tz6.2568@newsfe2-gui.ntli.net>

Sherm

Thanks - it doesn't work with IE 7 either!

David

"Sherm Pendley" <spamtrap@dot-app.org> wrote in message 
news:m264a8e6fr.fsf@local.wv-www.com...
> "David Walker" <david@cs.cf.ac.uk> writes:
>
>> Perhaps I have simply misunderstood what x-mixed-replace is supposed to 
>> do.
>> Any help would be appreciated.
>
> The same thing it's supposed to do if it's printed by Python, Ruby, or 
> some
> other language. Your question has nothing to do with Perl, it has to do 
> with
> HTTP and MIME, and more specifically, with one particular browser's 
> support
> for server push.
>
> At any rate, the answer is simple, I'm afraid - IE, at least up to and
> including IE 6, does not support server push with x-mixed-replace. Given
> the number of IE6 users still out there, that probably means you'll need
> to find another solution. :-(
>
> sherm--
>
> -- 
> Web Hosting by West Virginians, for West Virginians: http://wv-www.net
> Cocoa programming in Perl: http://camelbones.sourceforge.net 




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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V11 Issue 131
**************************************


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