[23653] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5860 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 26 11:06:02 2003

Date: Wed, 26 Nov 2003 08:05:09 -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           Wed, 26 Nov 2003     Volume: 10 Number: 5860

Today's topics:
    Re: Array contains too much data <noreply@gunnar.cc>
    Re: Array contains too much data <ubl@schaffhausen.de>
    Re: Assigning split to a list: undefined values? <mitia.nospam@northwestern.edu.invalid>
    Re: Assigning split to a list: undefined values? (Anno Siegel)
    Re: aternative grouping and map, deuglification <rev_1318@hotmail.com>
    Re: aternative grouping and map, deuglification (Sara)
    Re: Fetching Thomsonfn Realtime Data <Temp@NoSuchDomain.Info>
    Re: Image::Magick memory leak question <stanb@panix.com>
    Re: Image::Magick memory leak question <usenet@morrow.me.uk>
    Re: Perl Editor <bart.lateur@pandora.be>
        Perl Regex - Hex bytes <enon@erewhon.com>
    Re: Perl Regex - Hex bytes (Rafael Garcia-Suarez)
    Re: Perl Regex - Hex bytes <flavell@ph.gla.ac.uk>
        Regex Question <ccarpenter@erols.com>
    Re: Regex Question <hexkid@hotpop.com>
    Re: Regex Question <xx087@freenet.carleton.ca>
    Re: Regex Question <ccarpenter@erols.com>
    Re: Regexp issue . . . (Anno Siegel)
    Re: Regexp issue . . . <REMOVEsdnCAPS@comcast.net>
    Re: rename hash-key ? (Anno Siegel)
    Re: rename hash-key ? <abigail@abigail.nl>
    Re: rename hash-key ? (Anno Siegel)
    Re: rename hash-key ? (Rafael Garcia-Suarez)
    Re: system() never returns, how to kill it? <kalinaubears@iinet.net.au>
    Re: Unexpected tell() result <REMOVEsdnCAPS@comcast.net>
    Re: Using GetOptions twice in the script <mbax0apb@cs.man.ac.uk>
        Vandermonde matrices in PERL? (Andreas Wachhold)
    Re: Vandermonde matrices in PERL? (Anno Siegel)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 26 Nov 2003 15:52:14 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Array contains too much data
Message-Id: <bq2f08$1sg47k$1@ID-184292.news.uni-berlin.de>

Malte Ubl wrote:
> Gunnar Hjalmarsson wrote:
>>     my ($offset) = $ENV{QUERY_STRING} =~ /offset=(\d+)/;
>>     $offset ||= 0;
> 
> Why would you ever want to do that rather than,
> 
> my $q = CGI->new;
> <some code>
> my $offset = $q->param('offset') || 0;

Why not? After all, matching that string isn't very complicated.

Personally I sometimes refrain from using modules, when I still can
achieve what I want with a line or two. One reason may be that the
program I have spent most time writing is a program where efficiency
matters, even if it is a CGI scipt. (If you would benchmark the two
alternatives above, using the heavy-weight CGI.pm would appear
absurdly inefficient.)

Anyway, thanks for posting the module alternative. As long as OP does
not fully understand how the first alternative works, and under which
conditions, I agree that he should better use CGI.pm. On the other
hand, it's not advisable to write CGI scripts without learning the
basics about how CGI works, is it?

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



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

Date: Wed, 26 Nov 2003 16:30:45 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Array contains too much data
Message-Id: <bq2k1i$g5l$1@news.dtag.de>

Gunnar Hjalmarsson wrote:
> Personally I sometimes refrain from using modules, when I still can
> achieve what I want with a line or two. One reason may be that the
> program I have spent most time writing is a program where efficiency
> matters, even if it is a CGI scipt. (If you would benchmark the two
> alternatives above, using the heavy-weight CGI.pm would appear
> absurdly inefficient.)
> 
> Anyway, thanks for posting the module alternative. As long as OP does
> not fully understand how the first alternative works, and under which
> conditions, I agree that he should better use CGI.pm. On the other
> hand, it's not advisable to write CGI scripts without learning the
> basics about how CGI works, is it?

If you know how CGI works, you will write code that doesn't run under 
mod_perl or any other method of execution for that matter.

I for one appreciate every little bit I don't have to safe in my head.

BTW: The OP didn't even suggest he was using CGI :)

malte



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

Date: 26 Nov 2003 03:17:31 GMT
From: Dmitry Epstein <mitia.nospam@northwestern.edu.invalid>
Subject: Re: Assigning split to a list: undefined values?
Message-Id: <Xns943F17F08F155mitianorthwesternedu@63.218.45.21>

yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones) wrote in
news:3fc2aa3c@news.victoria.tc.ca: 

> Dmitry Epstein (mitia.nospam@northwestern.edu.invalid) wrote:
>: ko <kuujinbo@hotmail.com> wrote in
>: news:bpme0m$25q$1@pin3.tky.plala.or.jp: 
>: > Dmitry Epstein wrote:
>: >> Here is a code snippet:
>: >> 
>: >> while ($line = <F>) {
>: >>          my ($node1, $node2, $node3) = split ' ', $line;
>: >>          last unless defined $node3;
>: >>          ...
>: >> }
>: >> 
>: >> The idea here was that the loop stops if the line was
>: >> split into fewer than 3 values.  It doesn't work however:
>: >> when the line has only 2 values, the variable $node3 is
>: >> initialized with zero instead of remaining undefined.  How
>: >> come? 
>: >> 
>: >> (I have since changed the code to use an array instead of
>: >> a list.) 
>: >> 
>: > 
>: > Since the pattern ' ' is split()ing on whitespace, the
>: > newline on each line results in an empty trailing field
>: > ('', which is a defined value). So you need to get rid of
>: > the newline on each line: 
>: > 
>: > use strict;
>: > use warnings;
>: > 
>: > while (my $line = <DATA>) {
>: >    chomp $line;
>: >    my ($node1, $node2, $node3) = split ' ', $line;
>: >    last unless defined $node3;
>: >    print join(" ", $node1, $node2, $node3), "\n"
>: > }
>: > 
>: > __DATA__
>: > a s d
>: > a s
>: > 
>: > HTH- keith
> 
>: I don't think so.  Split on ' ' is supposed to "chomp" any
>: trailing whitespace.  In fact, if I use an array to store the
>: value of split instead of a list of scalars, the array does
>: not receive a null value in the end.
> 
> Not exactly.  The "default" behaviour is to drop empty
> trailing fields, but what does "default" mean?
> 
> perldoc -f split also states that assigning to a _list_ (which
> is what you have) creates an implicit limit on the number of
> fields to be extracted. 
> 
> So I am guessing that "default" is refering to the "limit",
> but since you have implicitly defined a limit then you don't
> get the default behaviour. 
> 
> Instead you get the first three fields, the third of which is
> the empty string "found" at the end.
> 
> 
>      "first-item  second-item \n"
>          1111111111  22222222222   3 (3rd is 0 chars long)

Heh, I didn't say my example was the "default" case (split with no 
arguments, as I understand it), now did I? :)  This is what the 
docs say:

As a special case, specifying a PATTERN of space (' ') will split 
on white space just as split with no arguments does.

There is a bit more on that case in the docs, but nowhere does it 
say that specifying a limit, whether implicitly or explicitly, 
somehow abrogates the standard behaviour of split on ' '.

Still confused.

-- 
Dmitry Epstein
Northwestern University, Evanston, IL.  USA
mitia(at)northwestern(dot)edu


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

Date: 26 Nov 2003 10:08:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Assigning split to a list: undefined values?
Message-Id: <bq1u2k$711$1@mamenchi.zrz.TU-Berlin.DE>

Dmitry Epstein  <mitia.nospam@northwestern.edu.invalid> wrote in comp.lang.perl.misc:
> yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones) wrote in
> news:3fc2aa3c@news.victoria.tc.ca: 
> > Dmitry Epstein (mitia.nospam@northwestern.edu.invalid) wrote:
> >: ko <kuujinbo@hotmail.com> wrote in
> >: news:bpme0m$25q$1@pin3.tky.plala.or.jp: 

> >: >> Here is a code snippet:
> >: >> 
> >: >> while ($line = <F>) {
> >: >>          my ($node1, $node2, $node3) = split ' ', $line;
> >: >>          last unless defined $node3;
> >: >>          ...
> >: >> }

[from the split doc]

> As a special case, specifying a PATTERN of space (' ') will split 
> on white space just as split with no arguments does.
> 
> There is a bit more on that case in the docs, but nowhere does it 
> say that specifying a limit, whether implicitly or explicitly, 
> somehow abrogates the standard behaviour of split on ' '.

Put these together (from the same document):

                                     If LIMIT is unspecified or
               zero, trailing null fields are stripped...

               When assigning to a list, if LIMIT is omitted, or
               zero, Perl supplies a LIMIT one larger than the
               number of variables in the list...

It isn't explicit, but in combination they say that trailing null fields
will *not* be stripped when assigning to a list.

Anno


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

Date: Wed, 26 Nov 2003 10:38:57 +0100
From: "Paul van Eldijk" <rev_1318@hotmail.com>
Subject: Re: aternative grouping and map, deuglification
Message-Id: <pan.2003.11.26.09.38.56.790585@hotmail.com>

On Tue, 25 Nov 2003 08:19:54 -0800 Sara wrote:

> I have a file like
> 
> CAT  4
> DOG  3
> CAT 6
> CAT 9
> BIRD 4
> DOG 13
> MOUSE 2
>   .
>   .
> 
> I'm trying to find lines with a certain starting word like
> 
>   @a = map /^((CAT|DOG).+)$/, @a;
> 
> What I WANT is actually all of the $1's (the whole line), but I get an
> array of the $1 and $2's instead. In this case I only wanted to use
> the parens to define the grouping of alternating substrings (as
> defined on p59 in Camel 2nd ed), but as a side-effect I end up with
> twice the size array as I expected.

Try:

  @a = map /^((?:CAT|DOG).+)$/, @a;

               ^^

That way, the second set of parentheses (with the ?: appended) acts as
clustering-only, without capturing.

See perldoc perlre for more info.

HTH,
Paul


-- 
$_=q{ ^4;c;14;1b:a^5;16:c^17:e^a;11;19:h^9;15:j^0:k^18:l^13
:n^6:o^7:p^10:r^b;12;1a:s^2:t^3;8:u^1};s{(?<=[;^])(\d)?([\d
abc])}{$a=$1;$2=~/([abc])/?$a*13+ord($1)%87:$1*13+$2}egx;
for(split/:/){($a,@_)=split/[;^]/;@@[@_]=($a)x@_}print@@



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

Date: 26 Nov 2003 07:12:54 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: aternative grouping and map, deuglification
Message-Id: <776e0325.0311260712.7b0c39cf@posting.google.com>

"Paul van Eldijk" <rev_1318@hotmail.com> wrote in message news:<pan.2003.11.26.09.38.56.790585@hotmail.com>...
> On Tue, 25 Nov 2003 08:19:54 -0800 Sara wrote:
> 
> > I have a file like
> > 
> > CAT  4
> > DOG  3
> > CAT 6
> > CAT 9
> > BIRD 4
> > DOG 13
> > MOUSE 2
> >   .
> >   .
> > 
> > I'm trying to find lines with a certain starting word like
> > 
> >   @a = map /^((CAT|DOG).+)$/, @a;
> > 
> > What I WANT is actually all of the $1's (the whole line), but I get an
> > array of the $1 and $2's instead. In this case I only wanted to use
> > the parens to define the grouping of alternating substrings (as
> > defined on p59 in Camel 2nd ed), but as a side-effect I end up with
> > twice the size array as I expected.
> 
> Try:
> 
>   @a = map /^((?:CAT|DOG).+)$/, @a;
> 
>                ^^
> 
> That way, the second set of parentheses (with the ?: appended) acts as
> clustering-only, without capturing.
> 
> See perldoc perlre for more info.
> 
> HTH,
> Paul

Seet! Thanks for the reply Paul- a nice trick. I may have seen this
before but its one of those used so infrequently that its easily
forgotten.

I wish other delimiters had been chosen for alternative grouping, like

  <CAT|DOG> 

Since Alterntaive grouping is often not related to capturing $-vars..

Cheers,
G


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

Date: Wed, 26 Nov 2003 11:20:35 GMT
From: "Picker Leon" <Temp@NoSuchDomain.Info>
Subject: Re: Fetching Thomsonfn Realtime Data
Message-Id: <700xb.334722$0v4.18766307@bgtnsc04-news.ops.worldnet.att.net>

Yes. I know it is a perl group. I just want to know how I can use Perl to
fetch the data. I am successful at fetching other sites which does not
require cookie or log in. I just want to know how people fetch data from
sites needing login, cookies, especially secssions, which I see not model in
Perl handles receiving sessions from server.

> Picker Leon <Temp@NoSuchDomain.Info> wrote in comp.lang.perl.misc:
> > Fetching Thomsonfn Realtime Data
> >
> > Thomsonfn provides the most accurate real-time data. Scottrader's data
is
> > not accurate 80% of the time. The only way for stock quote screamer is
to
> > use Quotetracker with scottrader data and before trade, double check
with
> > Thomsonfn.
> >
> > The author of Quotetrader refused to implement thomsonfn for an unknown
> > reason. I wonder if anyone here knows how to fetch data from thomsonfn
> > real-time?
> >
> > It seems to me that it uses cookies and it uses session key with its url
> > after each login. So the program must maintain a cookie jar and tracks
what
> > session the server sent back
>
> WTF are you on about?  This is a Perl newsgrup.
>
> Anno




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

Date: Wed, 26 Nov 2003 14:36:27 +0000 (UTC)
From: Stan Brown <stanb@panix.com>
Subject: Re: Image::Magick memory leak question
Message-Id: <bq2dpb$r19$1@reader2.panix.com>

In <slrnbs51u1.tru.mgjv@verbruggen.comdyn.com.au> Martien Verbruggen <mgjv@tradingpost.com.au> writes:

>On Mon, 24 Nov 2003 14:15:54 +0000 (UTC),
>	Stan Brown <stanb@panix.com> wrote:
>> In <bpjl3q$qps$2@wisteria.csv.warwick.ac.uk> Ben Morrow <usenet@morrow.me.uk> writes:
>> 
>> 
>>>Stan Brown <stanb@panix.com> wrote:
>>>> In <3fbc4f37.145998938@news2.news.adelphia.net>
>>>> posting.account@lynxview.com (William Herrera) writes:
>>>> Yes, it make perfect sense. I was naievly believing that since I had left
>>>> the subroutine, and the $image object was "local" to it, that all traces of
>>>> it would eb retruned to the free pool, as would be done, for non malloced
>>>> memory in C. 
>>>> 
>>>> This seems to be a pretty basic weakness of perl. I wonder if perl6
>>>> addresses this?
>> 
>>>No, this is a basic weakness of ImageMagick, or of C. Perl will
>>>correctly tell the Image::Magick object to free itself at the end of
>>>the scope: if it fails to do so correctly, this is not Perl's fault.
>> 
>> Well, OK. I guess I was thinking in a perfect world, perl would be in
>> charge of freeing all out of scope objects. Isn't that one og Java's claims
>> to fame? Or not, I know littel about Java.

>Perl does reference counting, and will "free" all objects that have no
>references to them anymore. Image::Magick objects are not pure Perl
>objects, however, but an XS wrapper around a C library. The memory
>leak can be anywhere inside that XS or C code.

>    return newSVpv("", 4096);

I'm not familar with the library call. Is it provided by a perl glue
libarary?

-- 
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
						-- Benjamin Franklin


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

Date: Wed, 26 Nov 2003 14:58:42 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Image::Magick memory leak question
Message-Id: <bq2f32$rf6$1@wisteria.csv.warwick.ac.uk>


Stan Brown <stanb@panix.com> wrote:
> In <slrnbs51u1.tru.mgjv@verbruggen.comdyn.com.au> Martien Verbruggen
> <mgjv@tradingpost.com.au> writes:
> >
> >    return newSVpv("", 4096);
> 
> I'm not familar with the library call. Is it provided by a perl glue
> libarary?

perldoc perlapi

-- 
$.=1;*g=sub{print@_};sub r($$\$){my($w,$x,$y)=@_;for(keys%$x){/main/&&next;*p=$
$x{$_};/(\w)::$/&&(r($w.$1,$x.$_,$y),next);$y eq\$p&&&g("$w$_")}};sub t{for(@_)
{$f&&($_||&g(" "));$f=1;r"","::",$_;$_&&&g(chr(0012))}};t    # ben@morrow.me.uk
$J::u::s::t, $a::n::o::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $.


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

Date: Wed, 26 Nov 2003 10:38:11 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Perl Editor
Message-Id: <bk09svkkvadb2okme6dmc0phap5u2dl0qk@4ax.com>

Paul Hovnanian P.E. wrote:

>AnnMarie wrote:
>> 
>> What is the best editor for Perl CGI-Scripts?
>
>Shouldn't this question be posted to an alt.religion group?

Nah... comp.religion is more like it.

-- 
	Bart.


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

Date: Wed, 26 Nov 2003 08:23:28 -0600
From: JEB <enon@erewhon.com>
Subject: Perl Regex - Hex bytes
Message-Id: <Xns943F5F9B5BA29mcruise@216.196.97.136>

I am trying to use Perl to rescue some legacy word processor files.
The files are ascii, except that some control codes use
bytes in the $80-$ff ranges.  I slurp the file into a string for editing.

Regex can hand the bytes <\x7f, but fails to recognize bytes that are \x80 
or above.

e.g.,

/\x03//; works
/\x81//; doesn't

Since I thought the problem might be related the adoption of unicode, I've 
tried various things like;

no encoding;
use bytes;
and various forms of encoding;
etc.

Nothing helped, but I may not have done it right.

I'm using Perl 5.8+(whatever the lastest revision is) with Redhat Linux 
8.0.

Is this something a Perl regex just can't handle?

JEB


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

Date: 26 Nov 2003 14:38:44 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Perl Regex - Hex bytes
Message-Id: <slrnbs9eid.t82.rgarciasuarez@rafael.serd.lyon.hexaflux.loc>

JEB wrote:
>
>/\x03//; works
>/\x81//; doesn't

You're giving too little information.
Could you post a sample code that demonstrates the problem, along with
your definition of "doesn't work" ? (warnings, error, expected result vs
actual result)

-- 
Unpopular is not *NIX


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

Date: Wed, 26 Nov 2003 14:44:31 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Perl Regex - Hex bytes
Message-Id: <Pine.LNX.4.53.0311261441120.1856@ppepc56.ph.gla.ac.uk>

On Wed, 26 Nov 2003, JEB wrote:

> I'm using Perl 5.8+(whatever the lastest revision is)

I suspect you're really using 5.8.0 (as opposed to 5.8.1).
 with Redhat Linux
> 8.0.

I think that's your clue.  Look for utf-8 in your linux locale
setting. It's confusing Perl 5.8.0 into using unicode mode.

(And read other discussions and FAQs on this issue).

Either change your locale setting to remove the reference
to utf-8 (I'm sure this works); or upgrade to 5.8.1, where this
coupling between locale and Perl default behaviour was found too
confusing and has been removed (so I'm told).

> Is this something a Perl regex just can't handle?

Wrong diagnosis.  Certainly it can handle it.



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

Date: Wed, 26 Nov 2003 14:09:46 GMT
From: "Chip" <ccarpenter@erols.com>
Subject: Regex Question
Message-Id: <Ku2xb.33138$m84.4801529@news1.news.adelphia.net>

Hi and thanks for your help.

I'm trying to parse the following :

Customer[Smith,John]Type[New]Source[Phone]Phone[5551212]

Since the brackets are metacharacters in perl I thought I
could just escape them with the following:

if (/Customer\[(.+),(.+)\]/) {   # parse out values
 $last = $1;
 $first = $2;
     }

But this does not work.  How should I escape the '[' and ']'
characters

Thanks
Chip




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

Date: 26 Nov 2003 14:18:14 GMT
From: Pedro Graca <hexkid@hotpop.com>
Subject: Re: Regex Question
Message-Id: <bq2cn5$1u56lv$1@ID-203069.news.uni-berlin.de>

Chip wrote:
> Since the brackets are metacharacters in perl I thought I
> could just escape them with the following:
>
> if (/Customer\[(.+),(.+)\]/) {   # parse out values


  if (/Customer\[([^,]+),([^\]]+)\]/) {   # parse out values
  
>  $last = $1;
>  $first = $2;
>      }
>
> But this does not work.  How should I escape the '[' and ']'
> characters

Your problem is that the second (.+) matches "John]Type[..."

-- 
            --= my mail address only accepts =--
	    --=   Content-Type: text/plain   =--


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

Date: 26 Nov 2003 14:25:44 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: Regex Question
Message-Id: <slrnbs9e0l.cfe.xx087@smeagol.ncf.ca>

Chip <ccarpenter@erols.com> wrote:
>  Customer[Smith,John]Type[New]Source[Phone]Phone[5551212]
>  
>  Since the brackets are metacharacters in perl I thought I
>  could just escape them with the following:
>  
>  if (/Customer\[(.+),(.+)\]/) {   # parse out values
>   $last = $1;
>   $first = $2;
>       }
>  
>  But this does not work.  How should I escape the '[' and ']'
>  characters

It does work, just not as you'd like.  Your subexpressions are too
greedy.

    my $s = 'Customer[Smith,John]Type[New]Source[Phone]Phone[5551212]';
    if ($s =~ /Customer\[(.+),(.+)\]/) {print "$1\n$2\n"}

results in:
    Smith
    John]Type[New]Source[Phone]Phone[5551212

Try
    /Customer\[(.+?),(.+?)\]/)


You might also try:
    my %data = split /[][]/, $s;
    my ($last, $first) = split /,/, $data{Customer};

-- 
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca


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

Date: Wed, 26 Nov 2003 15:21:25 GMT
From: "Chip" <ccarpenter@erols.com>
Subject: Re: Regex Question
Message-Id: <Vx3xb.33194$m84.4820595@news1.news.adelphia.net>

Thanks Glenn,

that works perfect

Chip
"Glenn Jackman" <xx087@freenet.carleton.ca> wrote in message
news:slrnbs9e0l.cfe.xx087@smeagol.ncf.ca...
> Chip <ccarpenter@erols.com> wrote:
> >  Customer[Smith,John]Type[New]Source[Phone]Phone[5551212]
> >
> >  Since the brackets are metacharacters in perl I thought I
> >  could just escape them with the following:
> >
> >  if (/Customer\[(.+),(.+)\]/) {   # parse out values
> >   $last = $1;
> >   $first = $2;
> >       }
> >
> >  But this does not work.  How should I escape the '[' and ']'
> >  characters
>
> It does work, just not as you'd like.  Your subexpressions are too
> greedy.
>
>     my $s = 'Customer[Smith,John]Type[New]Source[Phone]Phone[5551212]';
>     if ($s =~ /Customer\[(.+),(.+)\]/) {print "$1\n$2\n"}
>
> results in:
>     Smith
>     John]Type[New]Source[Phone]Phone[5551212
>
> Try
>     /Customer\[(.+?),(.+?)\]/)
>
>
> You might also try:
>     my %data = split /[][]/, $s;
>     my ($last, $first) = split /,/, $data{Customer};
>
> -- 
> Glenn Jackman
> NCF Sysadmin
> glennj@ncf.ca




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

Date: 26 Nov 2003 09:43:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Regexp issue . . .
Message-Id: <bq1ski$5sd$1@mamenchi.zrz.TU-Berlin.DE>

[comp.lang.perl deleted from newsgroups. it's dead]

MichaelC <mickyc@NOshaSPAMw.ca> wrote in comp.lang.perl.misc:
> "Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message
> news:Xns943E4EE1E1E8Dsdn.comcast@216.196.97.136...
> > -----BEGIN xxx SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > "MichaelC" <mickyc@NOshaSPAMw.ca> wrote in
> > news:d9Dwb.492453$9l5.241927@pd7tw2no:
> >
> > > Hi all.  I am having a particularly difficult time with a perl script
> > > that I am writing.  The problem area is a place where I need to strip
> > > some newlines out of a file.
> > >
> > > My source data is text which is in paragraph form, but has line breaks
> > > within the paragraphs.  I need to do as much processing as possible in
> > > order to minimise the amount of manual changes that I have to make.
> >
> > You don't say what you mean by "paragraph form".  If you're using that
> > term in the usual sense, then you mean that the paragraphs have double
> > newlines between them.  Is that so?  If so, Perl can read paragraph-at-a-
> > time for you:
> >
> >     $/ = '';
> >     $paragraph = <>;
> >
> 
> Sorry, I thought that I had defined my problem in
> enough detail.

In light of what you say now, your original problem description was
positively misleading.

>                 My problem is that the text that I am
> processing does NOT have double line breaks
> between paragraphs, and the text has been presented
> wrapped to 72 character width.  I do not have access
> to the original, as it was lost.  That is the reason for
> my current problem.
> That said, statistically, in the text that I am processing,
> the vast majority of lines that start with the set [A-Z"]
> will start a new paragraph.  The converse is als true,
> in that lines that start [a-z,.!?] are definitely part of a
> logical paragraph.  In that sense, I am not using the
> term "paragraph" in the way that you normally assume.
> 
> As an object example, the explanation above is a reasonable simulation of
> the problem that I am facing.  Logistically, the manually broken text is two
> paragraphs with no extra line breaks between them.  I neither require nor do
> I desire double line breaks between paragraphs, what I ro need, though, is
> each paragraph on a single line with a single line break at the end, and
> ONLY there.

The desired format you showed didn't indicate each paragraph should be
on one line.  There were plenty line breaks.  Neither did it show the
line break that would have had to precede "With DG ...".  There was
none.  How anyone was supposed to divine your intentions from that
description is your secret.

> For example, I need to strip all but two line breaks out of the example that
> I have provided, so that the text is contiguous from "Sorry, I" to "current
> problem." and from "That said, " to "normally assume."  After some thought,
> I found a solution:

Now you're talking about a different text.  None of the phrases "Sorry, I"
to "normally assume" appear in your original posting.  Is this some kind
of weird joke?

Your code below seems to do what you describe.

> #!/usr/bin/perl

    use warnings;
    use strict;

Code you present for discussion should run under strict and warnings.

> open(infl, "<in.txt" );
> open(outfl, ">out.txt");

It is customary to use upper-case filehandles:  INFL, OUTFL.

> while( <infl> ) {
> 
>   my $x = $_;

Why are you introducing the variable $x here?  It serves no purpose,
and you have to type more to apply pattern matching.

>   if ( $x =~ m!^[A-Z"]! ) { print outfl "\n"; }
>   $x =~ s!(^.+)\n!\1 !m;
                    ^^
"\1" is only valid in the regex part of a substitution.  Use $1 in
the replacement part.  If you had run it under warnings, you'd already
know this.

> 
>   print outfl $x;
> }
> 
> close(infl);
> close(outfl);

Anno


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

Date: Wed, 26 Nov 2003 06:35:05 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Regexp issue . . .
Message-Id: <Xns943F4D648B90sdn.comcast@216.196.97.136>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

"MichaelC" <mickyc@NOshaSPAMw.ca> wrote in
news:s5Vwb.496786$pl3.155625@pd7tw3no: 

> Sorry, I thought that I had defined my problem in
> enough detail.

I would say not.  :-)

>  My problem is that the text that I am
> processing does NOT have double line breaks
> between paragraphs, and the text has been presented
> wrapped to 72 character width.  I do not have access
> to the original, as it was lost.  That is the reason for
> my current problem.
> That said, statistically, in the text that I am processing,
> the vast majority of lines that start with the set [A-Z"]
> will start a new paragraph.  The converse is als true,
> in that lines that start [a-z,.!?] are definitely part of a
> logical paragraph.  In that sense, I am not using the
> term "paragraph" in the way that you normally assume.

It sounds like you want to remove all newlines, except where the newline 
is followed by an uppercase character.  Is that correct?

If so, I'd suggest reading the entire file into memory, and doing a 
simple substitution on it:

    $/ = undef;
    $content = <FILE>;
    $content =~ s/\n(?![[:upper:]])//g;

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP8SeSmPeouIeTNHoEQKoVQCfdSokT7bnrjmUOkqt4NVFOnp9A48An3t1
xj9Z1HMNOPOnq8PJ6NJF1KvR
=1T1p
-----END PGP SIGNATURE-----


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

Date: 26 Nov 2003 10:58:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: rename hash-key ?
Message-Id: <bq20vs$8p2$1@mamenchi.zrz.TU-Berlin.DE>

Jeff 'japhy' Pinyan  <pinyaj@rpi.edu> wrote in comp.lang.perl.misc:
> [posted & mailed]
> 
> On Tue, 25 Nov 2003, peter pilsl wrote:
> 
> >I need to rename a hashkey and wonder how to do it best.
> >
> >$hash->{newname}=$hash->{oldname}; 
> >delete $hash->{oldname};
> 
> delete() returns the key's value.
> 
>   $hash{new_key} = delete $hash{old_key};

Note that this isn't only shorter, it's also correcter :)

If the old and new key happen to be the same, the original code will
delete the key after re-assigning it, leaving it missing.  The one-line
version will first delete the key, then re-assign it, which amounts to
a no-op.  That is (usually) what should happen in that case.

Anno


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

Date: 26 Nov 2003 13:56:15 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: rename hash-key ?
Message-Id: <slrnbs9c7v.fe5.abigail@alexandra.abigail.nl>

Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMMDCCXXXIX
September MCMXCIII in <URL:news:bq20vs$8p2$1@mamenchi.zrz.TU-Berlin.DE>:
:)  Jeff 'japhy' Pinyan  <pinyaj@rpi.edu> wrote in comp.lang.perl.misc:
:) > [posted & mailed]
:) > 
:) > On Tue, 25 Nov 2003, peter pilsl wrote:
:) > 
:) > >I need to rename a hashkey and wonder how to do it best.
:) > >
:) > >$hash->{newname}=$hash->{oldname}; 
:) > >delete $hash->{oldname};
:) > 
:) > delete() returns the key's value.
:) > 
:) >   $hash{new_key} = delete $hash{old_key};
:)  
:)  Note that this isn't only shorter, it's also correcter :)
:)  
:)  If the old and new key happen to be the same, the original code will
:)  delete the key after re-assigning it, leaving it missing.  The one-line
:)  version will first delete the key, then re-assign it, which amounts to
:)  a no-op.  That is (usually) what should happen in that case.


Actually, it's not always a no-op. It's not a no-op if the hash is
tied, and it's also not a no-op in the sense that the order in
which keys() returns the keys may change.



Abigail
-- 
#!/opt/perl/bin/perl -w
$\ = $"; $; = $$; END {$: and print $:} $SIG {TERM} = sub {$ := $_}; kill 15 =>
fork and ($; == getppid and exit or wait) foreach qw /Just another Perl Hacker/


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

Date: 26 Nov 2003 14:02:07 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: rename hash-key ?
Message-Id: <bq2bov$eo5$2@mamenchi.zrz.TU-Berlin.DE>

Abigail  <abigail@abigail.nl> wrote in comp.lang.perl.misc:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMMDCCXXXIX
> September MCMXCIII in <URL:news:bq20vs$8p2$1@mamenchi.zrz.TU-Berlin.DE>:
> :)  Jeff 'japhy' Pinyan  <pinyaj@rpi.edu> wrote in comp.lang.perl.misc:
> :) > [posted & mailed]
> :) > 
> :) > On Tue, 25 Nov 2003, peter pilsl wrote:
> :) > 
> :) > >I need to rename a hashkey and wonder how to do it best.
> :) > >
> :) > >$hash->{newname}=$hash->{oldname}; 
> :) > >delete $hash->{oldname};
> :) > 
> :) > delete() returns the key's value.
> :) > 
> :) >   $hash{new_key} = delete $hash{old_key};
> :)  
> :)  Note that this isn't only shorter, it's also correcter :)
> :)  
> :)  If the old and new key happen to be the same, the original code will
> :)  delete the key after re-assigning it, leaving it missing.  The one-line
> :)  version will first delete the key, then re-assign it, which amounts to
> :)  a no-op.  That is (usually) what should happen in that case.
> 
> 
> Actually, it's not always a no-op. It's not a no-op if the hash is
> tied,

True.  A lot of things cease to be no-ops when tied variables (or overloaded
objects) enter the picture.

>       and it's also not a no-op in the sense that the order in
> which keys() returns the keys may change.

The order of hash keys is unpredictable.  It is still unpredictable after
the operation.

Anno


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

Date: 26 Nov 2003 14:43:57 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: rename hash-key ?
Message-Id: <slrnbs9es7.t82.rgarciasuarez@rafael.serd.lyon.hexaflux.loc>

Abigail wrote:
>Actually, it's not always a no-op. It's not a no-op if the hash is
>tied, and it's also not a no-op in the sense that the order in
>which keys() returns the keys may change.

It seems to me that the order of the keys() may change even after
a simple exists($hash{key}) with perl 5.8.2.

-- 
Urging is not *NIX


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

Date: Wed, 26 Nov 2003 20:51:10 +1100
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: system() never returns, how to kill it?
Message-Id: <3fc47857$0$1725$5a62ac22@freenews.iinet.net.au>

I. E. wrote:
> On 25 Nov 2003 16:43:23 GMT, Abigail <abigail@abigail.nl> wrote:
> 
> I tried using this method on Win32 but the system commnd still
> executes as a background process and consumes resources.  Is there any
> way to kill it on Win32?
> 

use Win32::Process;

if(!($process->Wait($milliseconds)) {
    $process->Kill();
    }
else {# process has already terminated}

Cheers,
Rob

-- 
To reply by email u have to take out the u in kalinaubears.



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

Date: Wed, 26 Nov 2003 06:22:33 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Unexpected tell() result
Message-Id: <Xns943F4B449EE06sdn.comcast@216.196.97.136>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones) wrote in
news:3fc3e934@news.victoria.tc.ca: 

> Dan Wilga (dwilga-MUNGE@mtholyoke.edu) wrote:
>: I'm seeing odd results when tell() is performed right after open with
>: append:
 ...
> You've opend the file in append mode, so any write is supposed to go
> to the end of the file, whereever that happens to be.  However, the
> size of the file could be changing due to another process, so the
> value of tell that you read at one moment doesn't really have any
> relation to where the data gets written.

Are you suggesting that some other process is writing to Dan's "foo" file 
in the millisecond between its creation and his call to tell()?

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP8SbW2PeouIeTNHoEQL+ygCg1DvH2pFCRIje8dhLbPvQulrwTcQAniMH
3Kzwo4rwlhw9UrbdBchxE1WP
=vem/
-----END PGP SIGNATURE-----


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

Date: Wed, 26 Nov 2003 10:25:28 +0000 (UTC)
From: Andrew Burgess <mbax0apb@cs.man.ac.uk>
Subject: Re: Using GetOptions twice in the script
Message-Id: <slrnbs8vso.bsl.a.burgess@ug065.cs.man.ac.uk>

From perldoc Getopt::Long, you could use:

  use Getopt::Long qw(:config pass_through);

to ignore unknown arguments and leave them in @ARGV. Alternatively you
can switch this feature on and off using calls to Configure().

The following seems to do what you want:

#!/usr/bin/perl

use strict;
use warnings;

use Getopt::Long qw(:config pass_through);

our ($a1, $a2, $a3, $b1, $b2, $b3);

getA();
getB();

sub getA {
  print "Parsing options in part A\n";
  GetOptions ( "a1" => \$a1,
               "a2"=> \$a2,
               "a3"=> \$a3);

  print "Got a1\n" if ($a1);
  print "Got a2\n" if ($a2);  
  print "Got a3\n" if ($a3);

}

sub getB {
  print "Parsing options in part B\n";
  GetOptions ( "b1" => \$b1,
               "b2"=> \$b2,
               "b3"=> \$b3);

  print "Got b1\n" if ($b1);
  print "Got b2\n" if ($b2);  
  print "Got b3\n" if ($b3);
}

HTH

Andrew


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

Date: 26 Nov 2003 00:45:28 -0800
From: night_blade@t-online.de (Andreas Wachhold)
Subject: Vandermonde matrices in PERL?
Message-Id: <13bddb54.0311260045.1f152969@posting.google.com>

Hello,

has anybody used this module?

http://search.cpan.org/~mlehmann/Algorithm-FEC-0.4/FEC.pm

I want to use it to pack tar files e.t.c. with forward error
correction. Do you have an example?

THANKS IN ADVANCE!!!


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

Date: 26 Nov 2003 10:17:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Vandermonde matrices in PERL?
Message-Id: <bq1uiv$711$2@mamenchi.zrz.TU-Berlin.DE>

Andreas Wachhold <night_blade@t-online.de> wrote in comp.lang.perl.misc:
> Hello,
> 
> has anybody used this module?
> 
> http://search.cpan.org/~mlehmann/Algorithm-FEC-0.4/FEC.pm
> 
> I want to use it to pack tar files e.t.c. with forward error
> correction. Do you have an example?

What have you tried so far?

Anno


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

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


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