[23178] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5399 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 20 18:10:41 2003

Date: Wed, 20 Aug 2003 15:10:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 20 Aug 2003     Volume: 10 Number: 5399

Today's topics:
    Re: OS/2 line feed question <flavell@mail.cern.ch>
    Re: OS/2 line feed question <matthew.garrish@sympatico.ca>
    Re: OS/2 line feed question <dave.nospam@ntlworld.com>
    Re: OT but hey <scripts_you_know_the_drill_@hudsonscripting.com>
    Re: OT but hey <scripts_you_know_the_drill_@hudsonscripting.com>
        Perl and Shockwave Multiuser protocol rolf.schaufelberger@web.de
    Re: Proper way to export structures from a module <skuo@mtwhitney.nsc.com>
    Re: Regular expression, getting href which is followed  <fatted@yahoo.com>
        to parse a list of records.... (Jim Carter)
    Re: to parse a list of records.... <skuo@mtwhitney.nsc.com>
    Re: to parse a list of records.... <krahnj@acm.org>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 20 Aug 2003 19:22:17 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: OS/2 line feed question
Message-Id: <Pine.LNX.4.53.0308201904400.6361@lxplus089.cern.ch>

On Wed, Aug 20, Dave Saville inscribed on the eternal scroll:

> >You don't give the impression of having read perldoc perlport where
> >it explains this ticklish issue.  Please do so, it will save a lot of
> >pointless detail in discussion.
>
> Two problems with that 1) you have to know there *is* such a document

Now that you mention it, there doesn't seem to be an obvious FAQ
pointing to it.  Is anyone from the FAQ maintainers listening??

%perldoc -q newline
No documentation for perl FAQ keyword `newline' found

> and 2) The build from sources of 5.8.0 on OS/2 does not seem to
> build/install perldoc and his dependencies.

That seems *most* unfortunate.  Perl comes with a substantial body of
documentation, most of it good, much of it excellent, though like any
community effort there are occasional rough edges.  Be that as it may,
every Perl installation should have the documentation in at least one
format!!  Activestate Perl (i.e for Win32) for example comes with a
conveniently-packaged HTML-ified version (though I needed to fit it
with my own stylesheet before I could read it - their fixed font sizes
were *microscopic* in my situation).  (But I digress.)

> HmmHmmbut I still don't understand why OS/2 sees everything as LF in
> text mode and Solaris can see the difference.

I have to admit I'm not familiar enough with OS/2 specifics, but I
assume it expects to get text from external files that are in "DOS"
format, and as such it would adjust the external CRLF format into
Perl's internal format (which on these platforms uses \012 to
represent \n).  The perlport document certainly rolls it in with DOS
and Windows platforms in -that- regard.

On unix-ish systems in general, the platform-native text format does
not use CR with its LF, and so -its- input/output routines provide no
such adjustment.

(Mac OS X might be different than other unix systems, I'm afraid I'm
no more familiar with that than I am with OS/2)



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

Date: Wed, 20 Aug 2003 14:59:28 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: OS/2 line feed question
Message-Id: <xyP0b.2689$c_.100378@news20.bellglobal.com>


"Alan J. Flavell" <flavell@mail.cern.ch> wrote in message
news:Pine.LNX.4.53.0308201904400.6361@lxplus089.cern.ch...

> Activestate Perl (i.e for Win32) for example comes with a
> conveniently-packaged HTML-ified version (though I needed to fit it
> with my own stylesheet before I could read it - their fixed font sizes
> were *microscopic* in my situation).  (But I digress.)
>

It would probably be helpful if they changed their install program to say
something more verbose than "View Release Notes" at the end. Even if it just
read "Viw Release Notes and Perl Documentation", more beginners might
realize what is popping open (I get the impression most don't chose to view
the notes, and it took me a couple of months before I even realized there
was a link in the Programs menu (I always went straight to the HTML folder
that is created)). Expecting that the average Windows user (with no *nix
exposure) will realize there is a documentation tool like perldoc on their
machine is also asking a lot, as most dos users will probably give up on
command line help after "perl /?".

Matt




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

Date: Wed, 20 Aug 2003 22:47:22 +0100 (BST)
From: "Dave Saville" <dave.nospam@ntlworld.com>
Subject: Re: OS/2 line feed question
Message-Id: <qnirfnivyyragyjbeyqpbz.hjy7qy7.pminews@text.news.ntlworld.com>

On Wed, 20 Aug 2003 19:22:17 +0200, Alan J. Flavell wrote:

>That seems *most* unfortunate.  Perl comes with a substantial body of
>documentation, most of it good, much of it excellent, though like any
>community effort there are occasional rough edges.  Be that as it may,
>every Perl installation should have the documentation in at least one
>format!!  Activestate Perl (i.e for Win32) for example comes with a
>conveniently-packaged HTML-ified version (though I needed to fit it
>with my own stylesheet before I could read it - their fixed font sizes
>were *microscopic* in my situation).  (But I digress.)

The docs are there - just perldoc & pod2man seem to have gone walkies
so I copied them over from the Solaris box and they work fine - at
least they did after I got a copy of less :-)

>
>> HmmHmmbut I still don't understand why OS/2 sees everything as LF in
>> text mode and Solaris can see the difference.
>
>I have to admit I'm not familiar enough with OS/2 specifics, but I
>assume it expects to get text from external files that are in "DOS"
>format, and as such it would adjust the external CRLF format into
>Perl's internal format (which on these platforms uses \012 to
>represent \n).  The perlport document certainly rolls it in with DOS
>and Windows platforms in -that- regard.
>
>On unix-ish systems in general, the platform-native text format does
>not use CR with its LF, and so -its- input/output routines provide no
>such adjustment.
>
>(Mac OS X might be different than other unix systems, I'm afraid I'm
>no more familiar with that than I am with OS/2)

Makes sense.


Regards

Dave Saville

NB switch saville for nospam in address




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

Date: Wed, 20 Aug 2003 16:20:12 -0700
From: hudson <scripts_you_know_the_drill_@hudsonscripting.com>
Subject: Re: OT but hey
Message-Id: <ca08kvk0arkg9l1lp7q1974q4ok19r1i63@4ax.com>

>so everybody can stop by. You can even get yourself a resume homepage with
>all details. :)
>
>-- 
>Matija

fine, I'll take the bait...thanks Matija, are you a virus writer?
anyway, here's some info that is probably you:

mpapec sail.hr, adresa: Bezimena bb 
tel.: 098/820 195 

Matija Papec
 
Croatia [Hrvatska]
matija.papec@bonus.fido.hr 




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

Date: Wed, 20 Aug 2003 16:33:01 -0700
From: hudson <scripts_you_know_the_drill_@hudsonscripting.com>
Subject: Re: OT but hey
Message-Id: <b818kvg27i3qele6l8m98rif1hquc8m7j2@4ax.com>

On Wed, 20 Aug 2003 16:20:12 -0700, hudson
<scripts_you_know_the_drill_@hudsonscripting.com> wrote:

>
>mpapec sail.hr, adresa: Bezimena bb 
>tel.: 098/820 195 
>
>Matija Papec
> 
>Croatia [Hrvatska]
>matija.papec@bonus.fido.hr 

Matija Papec, Varazdin

hmmm...I wonder if I could just call information and ask for your
telephone number ;-)


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

Date: Wed, 20 Aug 2003 22:56:28 +0200
From: rolf.schaufelberger@web.de
Subject: Perl and Shockwave Multiuser protocol
Message-Id: <bi0n9t$kti$05$2@news.t-online.com>

Hello,

has anybody written some code where perl talks to shockwave director using 
the Shockwave Multiuser protocol described in 
http://www.macromedia.com/support/director/ts/documents/smus_proto.htm
?
Haven't found anything at CPAN, but maybe somehow has written something 
like this before ?

Greetings

Rolf Schaufelberger
rolf.schaufelberger@web.de


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

Date: Wed, 20 Aug 2003 12:30:59 -0700
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: Proper way to export structures from a module
Message-Id: <Pine.GSO.4.21.0308201226460.20626-100000@mtwhitney.nsc.com>

On 20 Aug 2003, Steve D wrote:

> I had some problems properly exporting variables (actually complex
> reference structures) from a module with initialization inside of a
> BEGIN block.  By the time I arrived at a solution, I was no longer
> sure it was the best, or even a "proper", solution.  The key point
> seemed to be to use "our" for the items.
> 
> Any comments on the following code (two files) would be welcome:
> 
> ============== Test.pl ==================
> #! /bin/perl
> 
> use lib "." ;
> use strict ;
> use warnings ;
> use Tm ;
> use Tm qw( $MN) ;
> 
> push @$M, "2" ;
> $$MN{one} = 30;
> print "M: @$M, MN: $$MN{one}\n" ;
> 
> ============== Tm.pm ====================
> package Tm ;
> use strict ;
> use warnings ;
> use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION) ;
> use Exporter ;
> 
> @ISA = qw( Exporter ) ;
> 
> @EXPORT = qw ( $M ) ;
> @EXPORT_OK = qw ( $MN ) ;
> 
> our ( $M, $MN ) ;
> 
> BEGIN {
>     $M = [ 3 ] ;
>     $MN = { one => 20 } ;
> }
> 
> print "M: @$M, MN: $$MN{one}\n" ;
> 
> 1 ;
> =========================================
> 
> regards,
> Steve D
> 



You may want to consider using an object-oriented approach.  It
really depends on how complex your data structure is.   For example:


#!/usr/local/bin/perl

use strict ;
use warnings ;

# ============== Tm.pm ====================

package Tm ;

sub new {
    my $class = shift;
    my $self = { 
	array => [3],
        hash  => { one => 20 }
    };
    bless $self, $class;
    return $self;
}

sub access_array {
    my ($self, @stuff) = @_;
    if (@stuff) {
        push @{$self->{array}}, @stuff;
    }
    return $self->{array};
}

sub access_hash {
    my ($self,$key,$value) = @_;
    if (defined $key) {
	$self->{hash}{$key} = $value || undef;
    }
    return $self->{hash};
}

1 ;

package main;

use Data::Dumper;
# use Tm ;

my $thing = Tm->new();
my $aref = $thing->access_array(2);
my $href = $thing->access_hash('one',30);

print "ARRAY\n";
for (@$aref) {
    print "$_\n";
}

print "HASH\n";
while (my ($key, $value) = each %$href) {
    print "$key => $value\n";
}

-- 
Hope this helps,
Steven



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

Date: Wed, 20 Aug 2003 22:17:43 +0200
From: "Fatted" <fatted@yahoo.com>
Subject: Re: Regular expression, getting href which is followed by img tag with specific src
Message-Id: <3f43d6fe$0$147$1b62eedf@news.wanadoo.nl>

"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnbk6u8t.73q.tadmc@magna.augustmail.com...
> fatted <fatted@yahoo.com> wrote:

> You should use a module that understands HTML for processing HTML data.

Unfortunately I don't think that will help me with my problem, I want to
extract the value of a href, for an <a> tag, preceding an <img> tag which
has an attribute src with a specific value. I'm not sure what module does
this. (I'm going to look again though!)

> > Basically (but theres more!):
> ><a href="IwantThis.html"><img src="importantimage.gif"></a>
> >
> > (Un)Interesting part:
> > I first match a line
>
>
> "lines" do not matter in HTML.

Thanks for the reminder :) However if I were to use perl to parse a plain
text file (which just happened to contain html), "lines" :) do matter. I
first wanted to find the line (thereby ignoring all the rest of the html)
which contained the <img src="importantimage.gif" (there just happens to be
lots of tags on this line), and then try to find the preceding value of the
<a> tags href. I was trying to break the problem down (in my own little way
:)

> > So the line
>      ^^^^^^^^
>
> "the line" is singular, you didn't post 1 line, you posted 4 lines.

I posted 1 line (at least that was the attempt), unfortunately Google groups
did a bit of a hatchet job on it, and it got spread over 4 lines. Thats why
I referred to one line :)

> > actually looks something like this:
> ><a class="red" href="uninteresting.html" target="_new">Not so exciting
> > text</a><a href="equallyboring.html" class = "blue">yawn</a><a
> > class="green" href="IwantThis.html"><img border="0"
> > src="importantimage.gif" alt="MeMe"></a>
>
>
> If that _was_ really all on a single line, then it would still be
> equivalent HTML, since most whitespace does not matter in HTML data.
>
>    <br>
> and
>    <br         >
> and
>    <br
>    >
>
> Are all the same HTML data.

Revision is always good :)

> > open(FILE,"<","4body.html");
>
>
> You should always, yes *always*, check the return value from open():

I know, I know but I was working just on the regular expression in a tester
script, so it'd be obvious if there was a file problem, (my real script does
check for return value. Honest :). Good habits are good habits though.

>    open(FILE, '<', '4body.html') or die "could not open '4body.html' $!";
>
>
> > while(<FILE>)
> > {
> >         my $line = $_;
>
>
> If you want it in $line instead of $_ then you can put it
> in $line straightaway:
>
>    while ( my $line = <FILE> )

Good point.

> This will NOT do what you asked, because it does not handle
> arbitrary HTML, it handles only the one case that you have shown.

You're right it won't do what I asked, I think the google wrap, put you off.

> It can be easily broken by legal HTML.

I'll try to keep my HTML as bad as my perl code :)

> It would work correctly if I had used a module that understands
> HTML data...

See my first comment, but I'd be delighted to be proved wrong. In the mean
time, I'd still appreciate some tips on the regular expression...

> ------------------------------------
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my $html = '
> <a class="red" href="uninteresting.html" target="_new">Not so exciting
> text</a><a href="equallyboring.html" class = "blue">yawn</a><a
> class="green" href="IwantThis.html"><img border="0"
> src="importantimage.gif" alt="MeMe"></a>';
>
>
> while ( $html =~ m#(<a\s.*?</a>)#sg ) {
>    my $anchor = $1;
>    next unless $anchor =~ /src="importantimage\.gif"/;
>
>    print "$1\n" if  $anchor =~ /href="([^"]*)/;
> }






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

Date: 20 Aug 2003 12:35:25 -0700
From: carterave@yahoo.com (Jim Carter)
Subject: to parse a list of records....
Message-Id: <9c2a26b6.0308201135.6fd65868@posting.google.com>

Hi experts,

I have the below issue:

I have an input table like this:

-----            ----------           --------
Year              Quarter              Value
-----            ----------           -------- 
2003               Q1                   15.5
2003               Q1                   7.5
2003               Q2                   5.5
2003               Q4                   10
2003               Q4                   12.2
2003               Q2                   11
2004               Q1                   15.4
2004               Q2                   17
2004               Q4                   18
2004               Q3                   12.5
2004               Q4                   9.9
----------------------------------------------------

Now I want to populate the following combinations of year-quarter into
some variables ($a, $b, $c, $d etc) and summation calculations:

The combination should be in sequence (from youngest to oldest):

$a = concatenation of youngest combination (in this case, it is
2003-Q1).
$total1 = summation of all "Values" in the 2003-Q1 combination.
$b = concatenation of second youngest combination (in this case, it is
2003-Q2).
$total2 = summation of all "Values" in the 2003-Q2 combination.
$c = concatenation of third youngest combination (in this case, it is
2003-Q4).
$total3 = summation of all "Values" in the 2003-Q4 combination.
$d = concatenation of fourth youngest combination (in this case, it is
2004-Q1).
$total4 = summation of all "Values" in the 2004-Q1 combination.
$e = concatenation of fifth youngest combination (in this case, it is
2004-Q2).
$total4 = summation of all "Values" in the 2004-Q2 combination.
and so on....

Result should be :

$a = 2003-Q1
$value1 = 23
$b = 2003-Q2
$value2 = 16.5
$c = 2003-Q4
$value3 = 22.2
$d = 2004-Q1
$value4 = 15.4
$e = 2004-Q2
$value5 = 17
$f = 2004-Q3
$value6 = 12.5
$g = 2004-Q4
$value7 = 27.9

Can any one suggest a perl script to do this job? I am struggling with
the loops and arrays.

Thanks,
Jim


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

Date: Wed, 20 Aug 2003 12:54:06 -0700
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: to parse a list of records....
Message-Id: <Pine.GSO.4.21.0308201250240.20626-100000@mtwhitney.nsc.com>

On 20 Aug 2003, Jim Carter wrote:

> Hi experts,
> 
> I have the below issue:
> 
> I have an input table like this:
> 
> -----            ----------           --------
> Year              Quarter              Value
> -----            ----------           -------- 
> 2003               Q1                   15.5
> 2003               Q1                   7.5
> 2003               Q2                   5.5
> 2003               Q4                   10
> 2003               Q4                   12.2
> 2003               Q2                   11
> 2004               Q1                   15.4
> 2004               Q2                   17
> 2004               Q4                   18
> 2004               Q3                   12.5
> 2004               Q4                   9.9
> ----------------------------------------------------
> 
> Now I want to populate the following combinations of year-quarter into
> some variables ($a, $b, $c, $d etc) and summation calculations:
> 
> The combination should be in sequence (from youngest to oldest):

(snipped)


The names you've chosen for variables (e.g., $a, $b, etc.) aren't
very descriptive.


> Result should be :
> 
> $a = 2003-Q1
> $value1 = 23
> $b = 2003-Q2
> $value2 = 16.5
> $c = 2003-Q4
> $value3 = 22.2
> $d = 2004-Q1
> $value4 = 15.4
> $e = 2004-Q2
> $value5 = 17
> $f = 2004-Q3
> $value6 = 12.5
> $g = 2004-Q4
> $value7 = 27.9
> 
> Can any one suggest a perl script to do this job? I am struggling with
> the loops and arrays.
> 
> Thanks,
> Jim
> 


In this case, forego the array and use a hash:

#!/usr/local/bin/perl

use strict;
use warnings;

my %total;

while (<DATA>) {
    if (/^(\d{4})\s+(Q[1-4])\s+([\d.]+)/) {
	$total{"$1-$2"} += $3;
    }
}

for my $fy_quarter (sort keys %total) {
    printf "For $fy_quarter the total value was %0.2f\n", $total{$fy_quarter};
}

__DATA__
-----            ----------           --------
Year              Quarter              Value
-----            ----------           -------- 
2003               Q1                   15.5
2003               Q1                   7.5
2003               Q2                   5.5
2003               Q4                   10
2003               Q4                   12.2
2003               Q2                   11
2004               Q1                   15.4
2004               Q2                   17
2004               Q4                   18
2004               Q3                   12.5
2004               Q4                   9.9
----------------------------------------------------


-- 
Hope this helps,
Steven



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

Date: Wed, 20 Aug 2003 21:28:18 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: to parse a list of records....
Message-Id: <3F43E7D3.F1E4F722@acm.org>

Jim Carter wrote:
> 
> I have the below issue:
> I have an input table like this:
> -----            ----------           --------
> Year              Quarter              Value
> -----            ----------           --------
> 2003               Q1                   15.5
> 2003               Q1                   7.5
> 2003               Q2                   5.5
> 2003               Q4                   10
> 2003               Q4                   12.2
> 2003               Q2                   11
> 2004               Q1                   15.4
> 2004               Q2                   17
> 2004               Q4                   18
> 2004               Q3                   12.5
> 2004               Q4                   9.9
> ----------------------------------------------------
> 
> Now I want to populate the following combinations of year-quarter into
> some variables ($a, $b, $c, $d etc) and summation calculations:
> 
> The combination should be in sequence (from youngest to oldest):
> 
> $a = concatenation of youngest combination (in this case, it is 2003-Q1).
> $total1 = summation of all "Values" in the 2003-Q1 combination.
> $b = concatenation of second youngest combination (in this case, it is 2003-Q2).
> $total2 = summation of all "Values" in the 2003-Q2 combination.
> $c = concatenation of third youngest combination (in this case, it is 2003-Q4).
> $total3 = summation of all "Values" in the 2003-Q4 combination.
> $d = concatenation of fourth youngest combination (in this case, it is 2004-Q1).
> $total4 = summation of all "Values" in the 2004-Q1 combination.
> $e = concatenation of fifth youngest combination (in this case, it is 2004-Q2).
> $total4 = summation of all "Values" in the 2004-Q2 combination.
> and so on....
> 
> Result should be :
> 
> $a = 2003-Q1
> $value1 = 23
> $b = 2003-Q2
> $value2 = 16.5
> $c = 2003-Q4
> $value3 = 22.2
> $d = 2004-Q1
> $value4 = 15.4
> $e = 2004-Q2
> $value5 = 17
> $f = 2004-Q3
> $value6 = 12.5
> $g = 2004-Q4
> $value7 = 27.9
> 
> Can any one suggest a perl script to do this job? I am struggling with
> the loops and arrays.


You should probably use a hash, something like this:

$; = '-';
my %data;
while ( <DATA> ) {
    next unless /\d/;
    my @fields = split;
    $data{ $fields[0], $fields[1] } += $fields[2];
    }

for my $key ( sort keys %data ) {
    print "$key\t$data{$key}\n";
    }

__DATA__
-----            ----------           --------
Year              Quarter              Value
-----            ----------           --------
2003               Q1                   15.5
2003               Q1                   7.5
2003               Q2                   5.5
2003               Q4                   10
2003               Q4                   12.2
2003               Q2                   11
2004               Q1                   15.4
2004               Q2                   17
2004               Q4                   18
2004               Q3                   12.5
2004               Q4                   9.9
----------------------------------------------------



John
-- 
use Perl;
program
fulfillment


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

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

Ron wrote:

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

(---^


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

 ...
-- 
Bob Walton



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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 5399
***************************************


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