[19402] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1597 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 23 14:05:59 2001

Date: Thu, 23 Aug 2001 11:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <998589910-v10-i1597@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 23 Aug 2001     Volume: 10 Number: 1597

Today's topics:
    Re: Accessing $a and $b in conjunction with goto &NAME (Anno Siegel)
    Re: Accessing anonymous hash inside array?? <Tassilo.Parseval@post.rwth-aachen.de>
    Re: annoying habit of perl 5 in freebsd (Anno Siegel)
    Re: annoying habit of perl 5 in freebsd (Randal L. Schwartz)
    Re: annoying habit of perl 5 in freebsd (John J. Trammell)
    Re: annoying habit of perl 5 in freebsd (Anno Siegel)
        Can I include files with code in a new script? <erlend.stromsvik@hvorfor.no>
    Re: Can I include files with code in a new script? <ilya@martynov.org>
        Curses Parser? <downin@smarty.smart.net>
        Flock This <jtjohnston@courrier.usherb.ca>
        FTP (GET) in Perl ?!?! (Pete Sohi)
    Re: FTP (GET) in Perl ?!?! <tony_curtis32@yahoo.com>
    Re: FTP (GET) in Perl ?!?! <ilya@martynov.org>
        help with searching for occurances of...... (Paul)
    Re: help with searching for occurances of...... (John J. Trammell)
    Re: help with searching for occurances of...... (Tad McClellan)
        join <justin.devanandan.allegakoen@intel.com>
    Re: join (Anno Siegel)
    Re: join <mjcarman@home.com>
    Re: Partial matching of a regular expression (Malcolm Dew-Jones)
        Re-join <justin.devanandan.allegakoen@intel.com>
        reg exp..... <Martin.Bower@ib.bankgesellschaft.de>
    Re: reg exp..... <ilya@martynov.org>
    Re: reg exp..... <Martin.Bower@ib.bankgesellschaft.de>
    Re: reg exp..... <ilya@martynov.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 23 Aug 2001 15:47:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Accessing $a and $b in conjunction with goto &NAME
Message-Id: <9m38ho$att$1@mamenchi.zrz.TU-Berlin.DE>

According to W. James Showalter, Jr. <gamma@mintaka.iern.disa.mil>:
> 
> 
> On 23 Aug 2001, Anno Siegel wrote:
> 
> > According to W. James Showalter, Jr. <gamma@mintaka.iern.disa.mil>:
> > > Hello,
> > >
> > > I am using perl 5.6.0 on Solaris 8.
> > > Here is a fragment of a subroutine I use for sorting dotted values
> > > (e.g. OIDs and IP addresses).  It resides in a library package.
> > >
> > > sub ipsort {
> > >    my $pkg = (caller)[0];
> > >    my @a = split(/\./, ${"$pkg\::a"});
> >
> > Are you not running under strict?  ${"$pkg\::a"} is a symref.
> >
> > Anno
> >
> Anno,
> 
> Thanks for the response.  Regarding your comment above, I prefer to *not*
> use symrefs and always 'use strict' when it does not preclude me from
> doing something.
> 
> Since I need to qualify $a and $b in the module to the calling program's
> namespace I used a symref.  If there is a better way without using
> symrefs I would gladly employ it.

I don't think there is, and this may be one of the justified uses. I would
expect "no strict 'refs';" near the symref however.

If it is an option, you could forgo the problem and define complete
sorting function(s) (expecting and returning a list) in the module.

Or don't use $a and $b in your code and require the user to do

    sort { ipsort( $a, $b) } @list;

Since you are using split() in the comparison routine, the overhead
shouldn't matter much, but it is an inconvenience for the user.

Anno


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

Date: Thu, 23 Aug 2001 17:05:40 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Accessing anonymous hash inside array??
Message-Id: <3B851BC4.6080503@post.rwth-aachen.de>

Anno Siegel wrote:

> Not sure what you're getting at here?  $obj-- will remove the whole
> stack?  Or pop one item?  Interpret "$obj" as an address doesn't make
> any sense to me without context.

Ah, don't worry. :-) These were unfinished thoughts crossing my mind.
But as for "$obj": You probably know indirect adressing. Like in the 
AT&T WE32100, (%r0) would mean: Get the operand in the memory cell 
pointed to be %r0.

But as said: I am not yet sure what one could do with it. I have just 
used it once yet (for a simple overloading of "" => "$object" would 
return me a textual representation, just like $! does.)
Unfortunately (or, well, if you will: fortunately) there are so many 
other things in Perl I still haven't all tried. Currently I am 
investigating AUTOLOAD-stuff in classes, along with a little bit of 
HTML::Mason and mod_perl.

Tassilo
-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



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

Date: 23 Aug 2001 16:06:23 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: annoying habit of perl 5 in freebsd
Message-Id: <9m39lv$att$2@mamenchi.zrz.TU-Berlin.DE>

According to Villy Kruse <vek@pharmnl.ohout.pharmapartners.nl>:
> On Wed, 22 Aug 2001 17:51:16 GMT,
>     Uri Guttman <uri@sysarch.com> wrote:
> 
> 
> >>>>>> "JJT" == John J Trammell <trammell@haqq.hypersloth.invalid> writes:
> >
> >  JJT> On Thu, 23 Aug 2001 01:36:54 +0800, JH Foo <foojh@hotmail.com> wrote:
> >  >> It seems that Perl on Freebsd (4.3) has this annoying habit:
> >
> >  JJT> It's not a Perl thing, and it's not (just) a FreeBSD thing.
> >  JJT> It's a *nix thing.  One solution is:
> >
> >  JJT> print STDERR "x";
> >
> >or make stdout autoflush:
> >
> >	$|++ ;
> 
> 
> 
> Actualy I would do $|=1; .  If you want to set it to one just say so.
> No need to fetch the preveious value (whatever that might be) and
> increment it.  
> 
> BTW, $| is magic and can only have the values 0 and 1 regardless what
> value you assign to it.

Quite, for that reason I dislike the popular $|++ idiom.  It looks like
you could later restore the state with $|--, but that works only on
one level, not nested.  But as long as Randal uses it...

Anno


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

Date: 23 Aug 2001 09:13:03 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: annoying habit of perl 5 in freebsd
Message-Id: <m166be92ls.fsf@halfdome.holdit.com>

>>>>> "Anno" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:

Anno> Quite, for that reason I dislike the popular $|++ idiom.  It looks like
Anno> you could later restore the state with $|--, but that works only on
Anno> one level, not nested.  But as long as Randal uses it...

I use it mostly because it's all shifted and only three different keys
so I can type it faster.  "$| = 1;" requires a lot more
coordination. :)

I agree that it's also a bit more obscure.  I actually think I just
copied it from Larry's first documentation on the subject, and never
bothered to think that $| = 1 would be more "proper".

print "Just another Perl hacker," if ++$|;

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 23 Aug 2001 16:25:24 GMT
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: annoying habit of perl 5 in freebsd
Message-Id: <slrn9oaqpf.hte.trammell@haqq.hypersloth.net>

On 23 Aug 2001 09:13:03 -0700, Randal L. Schwartz <merlyn@stonehenge.com> wrote:
> >>>>> "Anno" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
> 
> Anno> Quite, for that reason I dislike the popular $|++ idiom.  It looks like
> Anno> you could later restore the state with $|--, but that works only on
> Anno> one level, not nested.  But as long as Randal uses it...
> 
> I use it mostly because it's all shifted and only three different keys
> so I can type it faster.  "$| = 1;" requires a lot more
> coordination. :)
> 
> I agree that it's also a bit more obscure.  I actually think I just
> copied it from Larry's first documentation on the subject, and never
> bothered to think that $| = 1 would be more "proper".

And all this fscking around with $| is why I just use STDERR.

-- 
I don't know what the hell is going on dude, but this suspension gives
me more time for fraggin'.  Yee haw!


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

Date: 23 Aug 2001 16:44:02 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: annoying habit of perl 5 in freebsd
Message-Id: <9m3bsi$dc8$1@mamenchi.zrz.TU-Berlin.DE>

According to Randal L. Schwartz <merlyn@stonehenge.com>:
> >>>>> "Anno" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
> 
> Anno> Quite, for that reason I dislike the popular $|++ idiom.  It looks like
> Anno> you could later restore the state with $|--, but that works only on
> Anno> one level, not nested.  But as long as Randal uses it...
> 
> I use it mostly because it's all shifted and only three different keys
> so I can type it faster.  "$| = 1;" requires a lot more
> coordination. :)

As good a reason as any, though less compelling from a European
perspective?  Why?  We get all kinds of keyboards, and only the position
of alpha-numerics is relatively predictable.  When it comes to the
placement of non-English characters people get inventive and usually
shuffle around some or all of the punctuation to save a key or two.
So relying on properties like "| is shifted" isn't done much.

And nobody touch-types.

Anno


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

Date: Thu, 23 Aug 2001 18:11:35 +0200
From: "Erlend Stromsvik" <erlend.stromsvik@hvorfor.no>
Subject: Can I include files with code in a new script?
Message-Id: <9m3a23$5ca5$1@ID-73903.news.dfncis.de>

Hi

I have a few scripts which do work on a database.
And now I have written som sub-functions for wrting logs etc., but I would
like to put that code in one file and then include that file with the
scripts.
So when I do a change to the logging-code I won't have to do manually
changes to every scripts that uses that log-code.

All the code are in sub's.


Regards
Erlend Stromsvik




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

Date: 23 Aug 2001 20:17:49 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Can I include files with code in a new script?
Message-Id: <87heuybviq.fsf@abra.ru>

>>>>> On Thu, 23 Aug 2001 18:11:35 +0200, "Erlend Stromsvik" <erlend.stromsvik@hvorfor.no> said:

ES> Hi
ES> I have a few scripts which do work on a database.
ES> And now I have written som sub-functions for wrting logs etc., but I would
ES> like to put that code in one file and then include that file with the
ES> scripts.
ES> So when I do a change to the logging-code I won't have to do manually
ES> changes to every scripts that uses that log-code.

ES> All the code are in sub's.

Use 'require' or 'use'. Read 'perldoc -tf require' and 'perldoc -tf use'.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: Thu, 23 Aug 2001 16:34:06 -0000
From: Dave Downin <downin@smarty.smart.net>
Subject: Curses Parser?
Message-Id: <toac3u1t5oai3d@corp.supernews.com>

I'm trying to write a web interface for a telnet based system.  The telnet 
based system uses curses for all of it's screens and menus.  Is there any perl 
module or piece of code that will take a string containing a curses based 
display and translate it to a fairly accurate plain ASCCI text representation?

-- 
Dave Downin (dave@arlo.net)
=============================================================================
        "Sorry, the world is nuts.  It can't be helped" - Arlo Guthrie
                       ArloNet - http://www.arlo.net/
=============================================================================
Any commercial e-mail sent to any of the above accounts will be automatically
rejected and subject to a $500 processing fee.


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

Date: Thu, 23 Aug 2001 16:10:39 GMT
From: jtjohnston <jtjohnston@courrier.usherb.ca>
Subject: Flock This
Message-Id: <3B852B7B.27AE98EC@courrier.usherb.ca>

Can someone show me how to do this better then?
Here I'm just reading, but flicking to make sure I don't interfer with
anyone writing at the same time.

     open(LOG,"$userlog") or die "can't open $userlog: $!\n";
     flock(LOG, 2);
     @STATData = <LOG>;
     close(LOG);

Here I'm appending some data:

     open(LOG,">$userlog") or die "can't open $userlog: $!\n";
     flock(LOG, 2);
     print LOG @STATData;
     print LOG "\n$tempid$temp11$temp12$temp13$temp14$temp21";
     close(LOG);

John



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

Date: 23 Aug 2001 08:41:41 -0700
From: amanpreet.sohi@sbs.siemens.co.uk (Pete Sohi)
Subject: FTP (GET) in Perl ?!?!
Message-Id: <1ab8c4be.0108230741.2849eed9@posting.google.com>

Oh wise ones!

Here's a quickie for you. (It could be a firewall problem but Im not
quite sure yet).

Im trying to FTP (GET) some files from a server down onto my local
machine but when running the Perl program get an error

"Can't call method "login" on an undefined value at
D:\GCat\FTP_dir\ftp2.pl line 4."

The code is as simple as follows:

=====================================================================
use Net::FTP;

    my $ftp = Net::FTP->new("ftp hubble", Debug => 0);
    $ftp->login("username", "password");   ##this line is flagged with
an error?!?!
    $ftp->cwd("/");
    $ftp->get("test.txt");
    $ftp->quit;
=====================================================================

Can you point me in the right direction?....I know the login
credentials are correct and Ive tried connecting through a DOS command
window and hey presto the site is fine, so I dont understand why this
isnt working.

Any help will do.

Cheers people.


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

Date: 23 Aug 2001 10:44:35 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: FTP (GET) in Perl ?!?!
Message-Id: <87pu9meq70.fsf@limey.hpcc.uh.edu>

>> On 23 Aug 2001 08:41:41 -0700,
>> amanpreet.sohi@sbs.siemens.co.uk (Pete Sohi) said:

> "Can't call method "login" on an undefined value at
> D:\GCat\FTP_dir\ftp2.pl line 4."

> The code is as simple as follows:

> =====================================================================
> use Net::FTP;

>     my $ftp = Net::FTP->new("ftp hubble", Debug => 0);
> $ftp->login("username", "password"); ##this line is
> flagged with an error?!?!  $ftp->cwd("/");
> $ftp->get("test.txt"); $ftp->quit;
> =====================================================================

It means the ftp connection was not created, and thus $ftp
is not a valid Net::FTP.  "ftp hubble" doesn't look like a
proper hostname, which is probably the cause.  You need to
check the return result from the new() before proceeding.

hth
t
-- 
Yes way!  Mmmmkay.


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

Date: 23 Aug 2001 19:47:36 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: FTP (GET) in Perl ?!?!
Message-Id: <87vgjebwx3.fsf@abra.ru>

>>>>> On 23 Aug 2001 08:41:41 -0700, amanpreet.sohi@sbs.siemens.co.uk (Pete Sohi) said:

PS> [..skip..]

PS> "Can't call method "login" on an undefined value at
PS> D:\GCat\FTP_dir\ftp2.pl line 4."

PS> The code is as simple as follows:

PS> =====================================================================
PS> use Net::FTP;

PS>     my $ftp = Net::FTP->new("ftp hubble", Debug => 0);
PS>     $ftp->login("username", "password");   ##this line is flagged with
PS> an error?!?!
PS>     $ftp->cwd("/");
PS>     $ftp->get("test.txt");
PS>     $ftp->quit;
PS> =====================================================================

Net::FTP->new(...) returns undef for some reason. This why your script
dies with message 'Can't call method "login" on an undefined value'.

This is from 'perldoc Net::FTP':

           If the constructor fails undef will be returned and an
           error message will be in $@

Check if $ftp is defined and it is not print $@ to find why.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: 23 Aug 2001 09:19:34 -0700
From: paul@orchidheathltd.freeserve.co.uk (Paul)
Subject: help with searching for occurances of......
Message-Id: <ba186de.0108230819.19b56171@posting.google.com>

Hi

I am new to perl and scripting (as you will gather!)

Having searched back through previous postings are unable to find
something similar to help.

I have a large data file that on each line contains a 6 digit ID
number. I would like to run a script to find, for each ID number (0 to
999999) how many times each one occurs in the file.

0=x occurances
1=x occurances
etc
etc
999999=x occurances

Output in this format would suffice.


Can anyone help?

Thanks in anticipation

Paul


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

Date: 23 Aug 2001 16:33:06 GMT
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: help with searching for occurances of......
Message-Id: <slrn9oar7t.hte.trammell@haqq.hypersloth.net>

On 23 Aug 2001 09:19:34 -0700, Paul wrote:
> I have a large data file that on each line contains a 6 digit ID
> number. I would like to run a script to find, for each ID number (0 to
> 999999) how many times each one occurs in the file.

my %count;

while (<>) { chomp; $count{$_}++; }

for (sort keys %count) { print "$_=$count{$_}\n" }

-- 
IAAMOAC.


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

Date: Thu, 23 Aug 2001 11:59:50 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: help with searching for occurances of......
Message-Id: <slrn9oaa3m.7eh.tadmc@tadmc26.august.net>

Paul <paul@orchidheathltd.freeserve.co.uk> wrote:
>
>I have a large data file that on each line contains a 6 digit ID
>number. I would like to run a script to find, for each ID number (0 to
>999999) how many times each one occurs in the file.
>
>0=x occurances
>1=x occurances
>etc
>etc
>999999=x occurances
>
>Output in this format would suffice.
>
>Can anyone help?


   perl -nle '$c{$_}++; END {print "$_=$c{$_}" for sort keys %c}' files...


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


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

Date: Thu, 23 Aug 2001 23:46:09 +0800
From: "Just in" <justin.devanandan.allegakoen@intel.com>
Subject: join
Message-Id: <9m3982$7ub@news.or.intel.com>

Its me again . . .

Appreciate the help given in spite of my vagueness . . .

Apart from joining the lines that end with misspelled words
(nice one Tad ; ), I am still stuck  . . .

Let me elaborate, a full line ends with a ;

The following is therefore split on to two lines :-
NAME       *     *        *    *        *      6130        1-9999  10%
 >0.5% N8  CHECKSETUP ;

So it should actually read:-
NAME       *     *        *    *        *      6130        1-9999  10%
>0.5% N8  CHECKSETUP;

Printing this out is fine using :-
$Line = $_;
s/\n// if((length($Line) < 60) && !(Line =~ /;$/));

However when I try sticking the joined current line into an array, like:-
@Array = split(" ", $Line);

I don't get anything returned from $Array[9] onwards.

Printing the length of $Line after all that suggests that it wasn't even
joined.

I'm not trying to modify $_ so I'm a bit stumped as to why $Array[9] eq ""
I've tried $NewLine = $PreviousLine . $CurrentLine and variations
of join " ", $CurrentLine, $NextLine but it results in the same empty
$Array[9].

What is it? Me, me or me?





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

Date: 23 Aug 2001 17:31:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: join
Message-Id: <9m3ekn$ffi$1@mamenchi.zrz.TU-Berlin.DE>

According to Just in <justin.devanandan.allegakoen@intel.com>:
> Its me again . . .
> 
> Appreciate the help given in spite of my vagueness . . .
> 
> Apart from joining the lines that end with misspelled words
> (nice one Tad ; ), I am still stuck  . . .
> 
> Let me elaborate, a full line ends with a ;
 
Okay, that's a word.

> The following is therefore split on to two lines :-
> NAME       *     *        *    *        *      6130        1-9999  10%
>  >0.5% N8  CHECKSETUP ;
> 
> So it should actually read:-
> NAME       *     *        *    *        *      6130        1-9999  10%
> >0.5% N8  CHECKSETUP;
> 
> Printing this out is fine using :-
> $Line = $_;
> s/\n// if((length($Line) < 60) && !(Line =~ /;$/));

Where is the length condition from?  Does that mean, a line shorter
than 60 characters doesn't need a ";" to be complete?

Anyway, all you do when you detect an incomplete line is to drop the
final "\n" from $_ (not from the copy in $line).  I fail to see how
this prints anything.

> However when I try sticking the joined current line into an array, like:-
> @Array = split(" ", $Line);

Joined where?  The code you show doesn't join lines.

[snip]

Since you can detect completed lines at sight (without peeking ahead
to the next line) code like this will work:

    my $coll = '';
    while ( <DATA> ) {
        chomp;
        $coll .= $_;
        if ( $coll =~ /;$/ ) { # condition for complete line in $coll
            # do something with $coll
            print "$coll\n"; # for instance, print it
            $coll = ''; # don't forget to reset when done
        }
    }

    print "Incomplete last line\n" if length $coll;

The if-condition tests for final ";".  Replace it with anything that
detects a completed line.

Anno


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

Date: Thu, 23 Aug 2001 12:45:03 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: join
Message-Id: <3B85411F.CC3B7423@home.com>

Just in wrote:
> 
> Let me elaborate, a full line ends with a ;

Now we have something. :)
 
> Printing this out is fine using :-
> $Line = $_;
> s/\n// if((length($Line) < 60) && !(Line =~ /;$/));

This doesn't join anything. It just strips the newline, which means that
lines will look joined when printed. It doesn't actually merge them in
memory.
 
> However when I try sticking the joined current line into an 
> array, like:-
> @Array = split(" ", $Line);
> 
> I don't get anything returned from $Array[9] onwards.
> 
> Printing the length of $Line after all that suggests that it wasn't
> even joined.

Because it wasn't.
 
> What is it? Me, me or me?

The second one. :) It would be best if you showed us the actual code,
instead of pieces out of context. But perhaps an example will help.

#!/usr/bin/perl -w
use strict;

while (my $line = <DATA>) {
    while ($line !~ /;$/) {
        $line =~ s/\n$/ /;
        $line .= <DATA>;
    }
    my @array = split(/ /, $line);
    print "$array[9]\n";
}

__DATA__
A1 2 3 4 5 6 7 8
9 10 11;
B1 2 3 4 5 6 7 8
9 10 11;
C1 2 3 4 5 6 7 8
9 10 11;


Or, you can change what Perl thinks of as a "line" by changing $/.

#!/usr/bin/perl -w
use strict;

{
    local $/ = ";\n";

    while (my $line = <DATA>) {
        $line =~ s/\n/ /g;
        my @array = split(/ /, $line);
        print "$array[9]\n";
    }
}

-mjc


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

Date: 23 Aug 2001 09:32:50 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Partial matching of a regular expression
Message-Id: <3b853032@news.victoria.tc.ca>

JP Belanger (jpbelang@hotmail.com) wrote:
: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones) wrote in message news:<3b842901@news.victoria.tc.ca>...

: > This may not be what you need, but sometimes you want to turn the test
: > around.
: > 
: > 	$input = <>;
: > 
: > 	print "partial match" if 'hello' =~ m/^${input}$/;

: This works for plain strings, but you can't use metacharacters.

use quotemeta to convert metachars into plain old text.

Another poster also pointed out a bug in my code - the trailing $
should not be there.


: What I actually want to do is match an expression by adding one
: character at a time (not a whole string) and poll the matcher to see
: if the string still could match.

: I don't think you can do this in Perl (TNWTDI :) ) short of writing 
: a matcher. Or maybe fooling around with the regular expression.

Well nothing can be done in any language, short of writing code or fooling
around with expressions. ;)



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

Date: Fri, 24 Aug 2001 00:01:15 +0800
From: "Just in" <justin.devanandan.allegakoen@intel.com>
Subject: Re-join
Message-Id: <9m39ce$811@news.or.intel.com>

Its me again . . .

Appreciate the help given in spite of my vagueness . . .

Apart from joining the lines that end with misspelled words
(nice one Tad ; ), I am still stuck  . . .

Let me elaborate, a full line ends with a ;

The following is therefore split on to two lines :-
NAME       *     *        *    *        *      6130        1-9999  10%
 >0.5% N8  CHECKSETUP ;

So it should actually read:-
NAME       *     *        *    *        *      6130        1-9999  10%
>0.5% N8  CHECKSETUP;

Printing this out is fine using :-
$Line = $_;
s/\n// if((length($Line) < 60) && !(Line =~ /;$/));

However when I try sticking the joined current line into an array, like:-
@Array = split(" ", $Line);

I don't get anything returned from $Array[9] onwards.

Printing the length of $Line after all that suggests that it wasn't even
joined.

I'm not trying to modify $_ so I'm a bit stumped as to why $Array[9] eq ""
I've tried $NewLine = $PreviousLine . $CurrentLine and variations
of join " ", $CurrentLine, $NextLine but it results in the same empty
$Array[9].

What is it? Me, me or me?







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

Date: Thu, 23 Aug 2001 18:05:16 +0200
From: Martin Bower <Martin.Bower@ib.bankgesellschaft.de>
Subject: reg exp.....
Message-Id: <3B8529BC.ABCC784B@ib.bankgesellschaft.de>

any kind person assist me with a regular expression please ?

I am trying to strip values from a SQL string, so that I will have the
following 3 values
$selection="name,type";
$tablename="sysobjects";
$where="type='U' or type='V'";
$orderby="type,lower(name)";

I'm struggling with the code below, I get varying results for the 2
example statements. Can anyone offer any help ?

and could I do all this one one regular expression rather than 4
individual ones ?



#!/usr/local/bin/perl -w
use strict;

# SELECT , FROM, WHERE and ORDER BY could be in upper or lower case
my $SQL ="SELECT name,type FROM sysobjects WHERE type='U' or type='V'
ORDER BY type,lower(name)";
#my $SQL ="SELECT name,type FROM sysobjects";

( my $selection = $SQL ) =~ s/^SELECT (.*) FROM .*/$1/;
( my $tablename = $SQL ) =~ s/.*[FROM|from] (\S+).*/$1/;

print "$selection\n";
print "$tablename\n";




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

Date: 23 Aug 2001 20:33:58 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: reg exp.....
Message-Id: <87d75mburt.fsf@abra.ru>

>>>>> On Thu, 23 Aug 2001 18:05:16 +0200, Martin Bower <Martin.Bower@ib.bankgesellschaft.de> said:

MB> any kind person assist me with a regular expression please ?
MB> I am trying to strip values from a SQL string, so that I will have the
MB> following 3 values
MB> $selection="name,type";
MB> $tablename="sysobjects";
MB> $where="type='U' or type='V'";
MB> $orderby="type,lower(name)";

MB> I'm struggling with the code below, I get varying results for the 2
MB> example statements. Can anyone offer any help ?

MB> and could I do all this one one regular expression rather than 4
MB> individual ones ?

MB> #!/usr/local/bin/perl -w
MB> use strict;

MB> # SELECT , FROM, WHERE and ORDER BY could be in upper or lower case
MB> my $SQL ="SELECT name,type FROM sysobjects WHERE type='U' or type='V'
MB> ORDER BY type,lower(name)";
MB> #my $SQL ="SELECT name,type FROM sysobjects";

MB> ( my $selection = $SQL ) =~ s/^SELECT (.*) FROM .*/$1/;
MB> ( my $tablename = $SQL ) =~ s/.*[FROM|from] (\S+).*/$1/;

MB> print "$selection\n";
MB> print "$tablename\n";

Somethink line this should work with only one regexp (untested)

#!/usr/local/bin/perl -w
use strict;
# SELECT , FROM, WHERE and ORDER BY could be in upper or lower case
my $SQL ="SELECT name,type FROM sysobjects WHERE type='U' or type='V'
ORDER BY type,lower(name)";
#my $SQL ="SELECT name,type FROM sysobjects";

my($selection, $tablename, $where, $orderby) =
    $SQL =~ /^SELECT (.*?) FROM (.*?) WHERE (.*?) ORDER BY (.*?)/i;

However it excects that SQL request parts are separated by single
space. Maybe you should replace ' ' with \s+. 

But IMHO you should look at CPAN module SQL::Statement.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: Thu, 23 Aug 2001 18:40:49 +0200
From: Martin Bower <Martin.Bower@ib.bankgesellschaft.de>
Subject: Re: reg exp.....
Message-Id: <3B853211.F57D5E8B@ib.bankgesellschaft.de>

thanks for the speedy reply.
If the WHERE and ORDER BY are optional,  how would I represent that ?

and am I right in saying that [FROM|from] would match either word "FROM" or "from" ?




> my($selection, $tablename, $where, $orderby) =
>     $SQL =~ /^SELECT (.*?) FROM (.*?) WHERE (.*?) ORDER BY (.*?)/i;
>
> However it excects that SQL request parts are separated by single
> space. Maybe you should replace ' ' with \s+.
>
> But IMHO you should look at CPAN module SQL::Statement.





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

Date: 23 Aug 2001 21:09:50 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: reg exp.....
Message-Id: <87d75mpush.fsf@abra.ru>

>>>>> On Thu, 23 Aug 2001 18:40:49 +0200, Martin Bower <Martin.Bower@ib.bankgesellschaft.de> said:

MB> thanks for the speedy reply.
MB> If the WHERE and ORDER BY are optional,  how would I represent that ?

/^SELECT (.*?) FROM (.*?)(?: WHERE (.*?))?(?: ORDER BY (.*?))?/i;

MB> and am I right in saying that [FROM|from] would match either word
MB> "FROM" or "from" ?

No. It will match single character. One of F, R, O, M, |, f, r, o, or m.

If you want to match FROM or from you should use (?:FROM|from). But if
you want just case insensitive match just use regexp option 'i'
(you can notice that I've used it).

>> my($selection, $tablename, $where, $orderby) =
>> $SQL =~ /^SELECT (.*?) FROM (.*?) WHERE (.*?) ORDER BY (.*?)/i;
>> 
>> However it excects that SQL request parts are separated by single
>> space. Maybe you should replace ' ' with \s+.
>> 
>> But IMHO you should look at CPAN module SQL::Statement.

But actually - don't reinvent the wheel. Just use SQL::Statement. It
will parse SQL queries for you.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: 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 1597
***************************************


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