[29667] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 911 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 6 09:09:59 2007

Date: Sat, 6 Oct 2007 06:09:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 6 Oct 2007     Volume: 11 Number: 911

Today's topics:
    Re: How to manipulate the cases of letters in a string? <tadmc@seesig.invalid>
        Load file into a hash <bill@ts1000.us>
    Re: Load file into a hash <mark.clementsREMOVETHIS@wanadoo.fr>
    Re: Load file into a hash <bill@ts1000.us>
    Re: More math than perl... xhoster@gmail.com
    Re: More math than perl... <paduille.4061.mumia.w+nospam@earthlink.net>
    Re: More math than perl... <ldolan@thinkinghatbigpond.net.au>
    Re: More math than perl... <veatchla@yahoo.com>
    Re: More math than perl... <paduille.4061.mumia.w+nospam@earthlink.net>
    Re: More math than perl... <bik.mido@tiscalinet.it>
    Re: More math than perl... <tadmc@seesig.invalid>
    Re: More math than perl... <bill@ts1000.us>
    Re: More math than perl... <bill@ts1000.us>
    Re: newbie question: find index of substr using regexp <tony@skelding.co.uk>
    Re: newbie question: find index of substr using regexp <nobull67@gmail.com>
    Re: newbie question: find index of substr using regexp <tadmc@seesig.invalid>
    Re: passing $fd as a reference <dontmewithme@got.it>
    Re: passing $fd as a reference <nobull67@gmail.com>
    Re: perl join on a non printable variable character ? <nobull67@gmail.com>
    Re: SIG{'PIPE'} <No_4@dsl.pipex.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 5 Oct 2007 19:28:50 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: How to manipulate the cases of letters in a string?
Message-Id: <slrnfgdlm2.tuj.tadmc@tadmc30.sbcglobal.net>

xz <zhang.xi.cn@gmail.com> wrote:
> On Oct 5, 3:15 am, Reinhard Pagitsch <r...@gmx.net> wrote:
>> Petr Vileta wrote:

>> And we have also the HTML documentation under \perl\html.

> Do you know where is this html documentation on linux?


    perldoc pod2html


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Sat, 06 Oct 2007 04:04:16 -0700
From:  Bill H <bill@ts1000.us>
Subject: Load file into a hash
Message-Id: <1191668656.358400.20730@r29g2000hsg.googlegroups.com>

Is there a "perl" way of loading a file directly into a hash instead
of using something like this quick example:

open(FILE,"test.txt");
while(<FILE>)
{
$line = $_;
chop $line;
@dbf = split(/\t/,$line);
$MYHASH{$dbf[0]} = $dbf[1];
}
close(FILE);

where the text file contains entries like this:

NAME0\tsome value
NAME1\tanother value

etc...  ?

Bill H



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

Date: Sat, 06 Oct 2007 13:19:06 +0200
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: Load file into a hash
Message-Id: <47076f2a$0$5104$ba4acef3@news.orange.fr>

Bill H wrote:
> Is there a "perl" way of loading a file directly into a hash instead
> of using something like this quick example:
> 
> open(FILE,"test.txt");
> while(<FILE>)
> {
> $line = $_;
> chop $line;
> @dbf = split(/\t/,$line);
> $MYHASH{$dbf[0]} = $dbf[1];
> }
> close(FILE);
> 
> where the text file contains entries like this:
> 
> NAME0\tsome value
> NAME1\tanother value
> 

C:\TEMP>cat loadarray.pl
#!perl

use strict;
use warnings;

use Data::Dumper;

my $filename = shift;
open my $fh,"<",$filename or die $!;

my %hash = map { chomp; split /\t/ } <$fh>;

print Dumper(\%hash);

close $fh or die $!;

C:\TEMP>cat data.txt
UK      London
France  Paris
Italy   Rome
USA     Washington
Germany Berlin

C:\TEMP>loadarray.pl data.txt
$VAR1 = {
           'France' => 'Paris',
           'UK' => 'London',
           'Italy' => 'Rome',
           'Germany' => 'Berlin',
           'USA' => 'Washington'
         };

C:\TEMP>

Mark


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

Date: Sat, 06 Oct 2007 04:32:27 -0700
From:  Bill H <bill@ts1000.us>
Subject: Re: Load file into a hash
Message-Id: <1191670347.508162.126670@y42g2000hsy.googlegroups.com>

On Oct 6, 7:19 am, Mark Clements <mark.clementsREMOVET...@wanadoo.fr>
wrote:
> Bill H wrote:
> > Is there a "perl" way of loading a file directly into a hash instead
> > of using something like this quick example:
>
> > open(FILE,"test.txt");
> > while(<FILE>)
> > {
> > $line = $_;
> > chop $line;
> > @dbf = split(/\t/,$line);
> > $MYHASH{$dbf[0]} = $dbf[1];
> > }
> > close(FILE);
>
> > where the text file contains entries like this:
>
> > NAME0\tsome value
> > NAME1\tanother value
>
> C:\TEMP>cat loadarray.pl
> #!perl
>
> use strict;
> use warnings;
>
> use Data::Dumper;
>
> my $filename = shift;
> open my $fh,"<",$filename or die $!;
>
> my %hash = map { chomp; split /\t/ } <$fh>;
>
> print Dumper(\%hash);
>
> close $fh or die $!;
>
> C:\TEMP>cat data.txt
> UK      London
> France  Paris
> Italy   Rome
> USA     Washington
> Germany Berlin
>
> C:\TEMP>loadarray.pl data.txt
> $VAR1 = {
>            'France' => 'Paris',
>            'UK' => 'London',
>            'Italy' => 'Rome',
>            'Germany' => 'Berlin',
>            'USA' => 'Washington'
>          };
>
> C:\TEMP>
>
> Mark- Hide quoted text -
>
> - Show quoted text -

I like that Mark. You basically took everything I had in the while
loop and put it on one line. Nice and neat.

Bill H



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

Date: 05 Oct 2007 22:37:00 GMT
From: xhoster@gmail.com
Subject: Re: More math than perl...
Message-Id: <20071005183703.033$C5@newsreader.com>

Bill H <bill@ts1000.us> wrote:
> Background:
>
> I have a routine I am writing in perl that will give me the median for
> a 0 to 5 rating. The ratings are stored in a file and I load the
> values into 7 different variables, RATE0 - RATE5 and one called TOTAL.
> When a person rates a page I increment one of  the RATE variables
> based on what they selected (0 - 5) and increment TOTAL so I have a
> running count (which is really just the sum of RATE0 - RATE5).
>
> The problem I have (and I hope I am explaining this right), to
> calculate a median, I have to make an array that contains all the
> values, sorted from low to high, and then look at the value of the
> element in the middle to get the median. As an example if I have the
> following (not real code, just an example of the logic):
>
> $RATE[0] = 3;
> $RATE[1] = 1;
> $RATE[2] = 0;
> $RATE[3] = 4;
> $RATE[4] = 1;
> $RATE[5] = 2;

Compute the median directly from the structure you already have.

use List::Util qw(sum);

sub median_from_bins {
  my ($bins,$total)=@_;
  $total=sum @$bins unless defined $total;
  my $sofar=0;
  for (my $x=0; $x<=5; $x++) {
     $sofar+=$bins->[$x];
     return $x if $sofar>$total/2;
     if ($sofar == $total/2) {
        my $y=$x+1;
        $y++ until $bins->[$y];
        return ($x+$y)/2;
  };
  die "Should never get here $x $sum $total @$bins";
};

my $median = median_from_bins(\@RATE,$TOTAL);

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: Fri, 05 Oct 2007 16:49:31 -0500
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: More math than perl...
Message-Id: <13gdgc7f75goof4@corp.supernews.com>

On 10/05/2007 04:12 PM, Bill H wrote:
> [...]
> And the median would be $ARRAY[5] or 3. With an even number of
> elements in @ARRAY I have to add the value below the middle and the
> value above the middle, divide by 2 to get the median.
> 
> For a small sample this is no problem, but when the number of people
> who have rated it get in to the 1000's this array is going to be too
> cumbersome. Does anyone know of a simpler way to do it in perl without
> adding in modules or using alot of memory?
> [...]

I would just build the array in memory. On any reasonably modern system, 
you'll have to have millions of values before you run out of memory.

I know the mean can be calculated "on the fly"--without storing all of 
the values to be examined, but I can't see how this is to be done with 
the median; I don't think it's possible.

PS.
I would have given this post a more descriptive subject line like: 
calculating median without using too much memory.


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

Date: Sat, 06 Oct 2007 01:40:27 GMT
From: "Peter Jamieson" <ldolan@thinkinghatbigpond.net.au>
Subject: Re: More math than perl...
Message-Id: <fIBNi.5975$H22.3554@news-server.bigpond.net.au>


"Bill H" <bill@ts1000.us> wrote in message 
news:1191618738.361537.183720@o3g2000hsb.googlegroups.com...
> Background:
>
> I have a routine I am writing in perl that will give me the median for
> a 0 to 5 rating. The ratings are stored in a file and I load the
> values into 7 different variables, RATE0 - RATE5 and one called TOTAL.
> When a person rates a page I increment one of  the RATE variables
> based on what they selected (0 - 5) and increment TOTAL so I have a
> running count (which is really just the sum of RATE0 - RATE5).
>
> The problem I have (and I hope I am explaining this right), to
> calculate a median, I have to make an array that contains all the
> values, sorted from low to high, and then look at the value of the
> element in the middle to get the median. As an example if I have the
> following (not real code, just an example of the logic):
>
> $RATE[0] = 3;
> $RATE[1] = 1;
> $RATE[2] = 0;
> $RATE[3] = 4;
> $RATE[4] = 1;
> $RATE[5] = 2;
>
> Then my array would be:
>
> @ARRAY = (0,0,0,1,3,3,3,3,4,5,5);
>
> And the median would be $ARRAY[5] or 3. With an even number of
> elements in @ARRAY I have to add the value below the middle and the
> value above the middle, divide by 2 to get the median.
>
> For a small sample this is no problem, but when the number of people
> who have rated it get in to the 1000's this array is going to be too
> cumbersome. Does anyone know of a simpler way to do it in perl without
> adding in modules or using alot of memory?
>
> Any / all ideas are welcomed, but please remember that the example I
> gave is just typed to give you an idea and is not any real code I am
> using.
>
> Bill H
>

Bill, If keeping memory use low is a priority and you indeed need the median
of thousands of ratings then for your data you can probably safely use the 
mean value
since as your data count increases the mean and median will converge.
INT($mean) could give you a whole number if needed.
Cheers, Peter 




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

Date: Fri, 05 Oct 2007 21:55:17 -0500
From: l v <veatchla@yahoo.com>
Subject: Re: More math than perl...
Message-Id: <13gdu8765prpdd0@news.supernews.com>

Bill H wrote:
> Background:
> 
> I have a routine I am writing in perl that will give me the median for
> a 0 to 5 rating. The ratings are stored in a file and I load the
> values into 7 different variables, RATE0 - RATE5 and one called TOTAL.
> When a person rates a page I increment one of  the RATE variables
> based on what they selected (0 - 5) and increment TOTAL so I have a
> running count (which is really just the sum of RATE0 - RATE5).
> 
> The problem I have (and I hope I am explaining this right), to
> calculate a median, I have to make an array that contains all the
> values, sorted from low to high, and then look at the value of the
> element in the middle to get the median. As an example if I have the
> following (not real code, just an example of the logic):
> 
> $RATE[0] = 3;
> $RATE[1] = 1;
> $RATE[2] = 0;
> $RATE[3] = 4;
> $RATE[4] = 1;
> $RATE[5] = 2;
> 
> Then my array would be:
> 
> @ARRAY = (0,0,0,1,3,3,3,3,4,5,5);
> 
> And the median would be $ARRAY[5] or 3. With an even number of
> elements in @ARRAY I have to add the value below the middle and the
> value above the middle, divide by 2 to get the median.
> 
> For a small sample this is no problem, but when the number of people
> who have rated it get in to the 1000's this array is going to be too
> cumbersome. Does anyone know of a simpler way to do it in perl without
> adding in modules or using alot of memory?
> 
> Any / all ideas are welcomed, but please remember that the example I
> gave is just typed to give you an idea and is not any real code I am
> using.
> 
> Bill H
> 


use strict;
use warnings;
@ARRAY = (0,0,0,1,3,3,3,3,4,5,5);

# using the same array since you are concerned about memory.
# need to load the array to handle sorting of 2 digit numbers.
@ARRAY = sort map {sprintf "%05d", $_} @ARRAY;
$midPoint = $#ARRAY / 2;
$median = $ARRAY[int $midPoint];

if ($midPoint != int $midPoint) {
	$upperPoint = $midPoint +1;
	$median = ($median + $ARRAY[int $upperPoint]) / 2;
}

print "median = $median\n";


But this is why I use the Statistics::Descriptive::Discrete module to 
calculate medians.

-- 

Len


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

Date: Sat, 06 Oct 2007 00:56:07 -0500
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: More math than perl...
Message-Id: <13ge903bdlj7g20@corp.supernews.com>

On 10/05/2007 09:55 PM, l v wrote:
> Bill H wrote:
>> [ problem calculating the median without using too much memory ]
>> Bill H
>>
> 
> 
> use strict;
> use warnings;
> @ARRAY = (0,0,0,1,3,3,3,3,4,5,5);

This kind of array is what Bill wanted to avoid creating.

> 
> # using the same array since you are concerned about memory.
> # need to load the array to handle sorting of 2 digit numbers.
> @ARRAY = sort map {sprintf "%05d", $_} @ARRAY;

How is that simpler than this?

@ARRAY = sort { $a <=> $b } @ARRAY;

> $midPoint = $#ARRAY / 2;
> $median = $ARRAY[int $midPoint];
> 
> if ($midPoint != int $midPoint) {
>     $upperPoint = $midPoint +1;
>     $median = ($median + $ARRAY[int $upperPoint]) / 2;
> }
> 
> print "median = $median\n";
> 

use POSIX 'ceil';
print "median = ", $ARRAY[ceil(@ARRAY/2)], "\n";

> 
> But this is why I use the Statistics::Descriptive::Discrete module to 
> calculate medians.
> 

Bill said he didn't want to use any modules.



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

Date: Sat, 06 Oct 2007 12:23:05 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: More math than perl...
Message-Id: <jeoeg3djr29ft19ueqhse9cjhj32qrp53o@4ax.com>

On 05 Oct 2007 17:44:43 -0400, Charlton Wilbur
<cwilbur@chromatico.net> wrote:

>if (@array % 2)
>{
>  $median = ($array[(@array-1)/2] + $array[(@array+1)/2])/2;
>}
>else
>{
>  $median = $array[@array/2];        
>}

Actually, AIUI the index of latter should be (@array-1)/2 (or
$#array/2) and the two should calculations should be swapped. Of
course, this is IMHO a good place where to use the ternary conditional
operator.[*]


[*] On a second thought, do "of course" and "IMHO" clash?


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Fri, 5 Oct 2007 19:34:26 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: More math than perl...
Message-Id: <slrnfgdm0i.tuj.tadmc@tadmc30.sbcglobal.net>

Bill H <bill@ts1000.us> wrote:
> On Oct 5, 5:44 pm, Charlton Wilbur <cwil...@chromatico.net> wrote:
>> >>>>> "BH" == Bill H <b...@ts1000.us> writes:
>>
>>     BH> The problem I have (and I hope I am explaining this right), to
>>     BH> calculate a median, I have to make an array that contains all
>>     BH> the values, sorted from low to high, and then look at the
>>     BH> value of the element in the middle to get the median.


>> Alternately, if you did the sensible thing and kept $RATE0 through
>> $RATE5 in an array, you could say, much more elegantly,
>>
>> my @array = map { ($_) x $RATE[$_] } (0..5);

>> --
>> Charlton Wilbur
>> cwil...@chromatico.net


[ it is bad 'net manners to quote .sigs ...]


> Thanks Charlton, but would this not still make a large array if the
> total number of people is high (unles I am missing something in it).


How many hundreds of thousands of people do you expect
will take your survey?


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Sat, 06 Oct 2007 04:01:12 -0700
From:  Bill H <bill@ts1000.us>
Subject: Re: More math than perl...
Message-Id: <1191668472.528378.144360@o3g2000hsb.googlegroups.com>

On Oct 6, 1:56 am, "Mumia W." <paduille.4061.mumia.w
+nos...@earthlink.net> wrote:
> On 10/05/2007 09:55 PM, l v wrote:
>
> > Bill H wrote:
> >> [ problem calculating the median without using too much memory ]
> >> Bill H
>
> > use strict;
> > use warnings;
> > @ARRAY = (0,0,0,1,3,3,3,3,4,5,5);
>
> This kind of array is what Bill wanted to avoid creating.
>
>
>
> > # using the same array since you are concerned about memory.
> > # need to load the array to handle sorting of 2 digit numbers.
> > @ARRAY = sort map {sprintf "%05d", $_} @ARRAY;
>
> How is that simpler than this?
>
> @ARRAY = sort { $a <=> $b } @ARRAY;
>
> > $midPoint = $#ARRAY / 2;
> > $median = $ARRAY[int $midPoint];
>
> > if ($midPoint != int $midPoint) {
> >     $upperPoint = $midPoint +1;
> >     $median = ($median + $ARRAY[int $upperPoint]) / 2;
> > }
>
> > print "median = $median\n";
>
> use POSIX 'ceil';
> print "median = ", $ARRAY[ceil(@ARRAY/2)], "\n";
>
>
>
> > But this is why I use the Statistics::Descriptive::Discrete module to
> > calculate medians.
>
> Bill said he didn't want to use any modules.

Thanks for the help guys. I ended up using a combination of the
examples given:


sub getMedian
{
    my @values = @_;
    my @median = map { ($_) x $values[$_] } (0..5);
    my $m = int(@median / 2);
    if ($m != @median / 2)
    {
        $m = int(($median[$m] + $median[$m + 1]) / 2);
    }
    else
    {
        $m = $median[$m];
    }
    return ($m);
}

where I call it with:

$median = getMedian(@RATE);

I do end up creating the array, but I think it will be ok.

Bill H



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

Date: Sat, 06 Oct 2007 06:06:21 -0700
From:  Bill H <bill@ts1000.us>
Subject: Re: More math than perl...
Message-Id: <1191675981.873467.299980@w3g2000hsg.googlegroups.com>

On Oct 6, 7:01 am, Bill H <b...@ts1000.us> wrote:
> On Oct 6, 1:56 am, "Mumia W." <paduille.4061.mumia.w
>
>
>
>
>
> +nos...@earthlink.net> wrote:
> > On 10/05/2007 09:55 PM, l v wrote:
>
> > > Bill H wrote:
> > >> [ problem calculating the median without using too much memory ]
> > >> Bill H
>
> > > use strict;
> > > use warnings;
> > > @ARRAY = (0,0,0,1,3,3,3,3,4,5,5);
>
> > This kind of array is what Bill wanted to avoid creating.
>
> > > # using the same array since you are concerned about memory.
> > > # need to load the array to handle sorting of 2 digit numbers.
> > > @ARRAY = sort map {sprintf "%05d", $_} @ARRAY;
>
> > How is that simpler than this?
>
> > @ARRAY = sort { $a <=> $b } @ARRAY;
>
> > > $midPoint = $#ARRAY / 2;
> > > $median = $ARRAY[int $midPoint];
>
> > > if ($midPoint != int $midPoint) {
> > >     $upperPoint = $midPoint +1;
> > >     $median = ($median + $ARRAY[int $upperPoint]) / 2;
> > > }
>
> > > print "median = $median\n";
>
> > use POSIX 'ceil';
> > print "median = ", $ARRAY[ceil(@ARRAY/2)], "\n";
>
> > > But this is why I use the Statistics::Descriptive::Discrete module to
> > > calculate medians.
>
> > Bill said he didn't want to use any modules.
>
> Thanks for the help guys. I ended up using a combination of the
> examples given:
>
> sub getMedian
> {
>     my @values = @_;
>     my @median = map { ($_) x $values[$_] } (0..5);
>     my $m = int(@median / 2);
>     if ($m != @median / 2)
>     {
>         $m = int(($median[$m] + $median[$m + 1]) / 2);
>     }
>     else
>     {
>         $m = $median[$m];
>     }
>     return ($m);
>
> }
>
> where I call it with:
>
> $median = getMedian(@RATE);
>
> I do end up creating the array, but I think it will be ok.
>
> Bill H- Hide quoted text -
>
> - Show quoted text -

After playing with it for awhile I wonder if median is what I really
need. Logically, if you have 60 people rate the page at 0 and 30
people rate it at 5 then the page rating should be somewhere between 1
and 2, but using a median it would still be ranked at a 0 (middle
element in the array would be a 0). I know it aint strictly perl, but
any thoughts?

Bill H



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

Date: Fri, 05 Oct 2007 17:54:56 -0700
From:  Mintcake <tony@skelding.co.uk>
Subject: Re: newbie question: find index of substr using regexp
Message-Id: <1191632096.483505.72400@k79g2000hse.googlegroups.com>

On Oct 6, 2:53 am, Jim Gibson <jgib...@mail.arc.nasa.gov> wrote:
> In article
> <Pine.WNT.4.64.0710050944340.3...@ctfanxnfba.unjnvvnaryrpgevp.arg>,
>
> Sean Nakasone <seannakas...@yahoo.com> wrote:
> > ok i guess i'll be using this.  thanks for your help
>
> > use strict;
> > use warnings;
>
> > my $a = "  quick brown";
> > $a =~ /[^ ]/;
> > print (length($`));
>
> Don't use any of the RE special variables unless the match succeeded:
>
> if( $a =~ /[^ ]/ ) {
>   print (length($`));
>
> }
>
> --
> Jim Gibson
>
>  Posted Via Usenet.com Premium Usenet Newsgroup Services
> ----------------------------------------------------------
>     ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
> ----------------------------------------------------------        
>                http://www.usenet.com

This is just a shot in the dark but it sounds to me like you just want
to remove leading whitespace from the string - in which case...

$a =~ s/\s*//;




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

Date: Sat, 06 Oct 2007 10:29:27 -0000
From:  Brian McCauley <nobull67@gmail.com>
Subject: Re: newbie question: find index of substr using regexp
Message-Id: <1191666567.009316.27280@o3g2000hsb.googlegroups.com>

On Oct 5, 8:19 pm, Jim Gibson <jgib...@mail.arc.nasa.gov> wrote:
> In article
> You can use the length of the $` variable, which is set to the
> substring to the left of the match (but be aware of the speed penalty
> for doing so

 ... so use $-[0] instead. $-[0] has the same value as length($`)
without the penalty.



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

Date: Fri, 5 Oct 2007 19:26:27 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: newbie question: find index of substr using regexp
Message-Id: <slrnfgdlhj.tuj.tadmc@tadmc30.sbcglobal.net>

Sean Nakasone <seannakasone@yahoo.com> wrote:
> ok i guess i'll be using this.  thanks for your help
>
>
> use strict;
> use warnings;
>
> my $a = "  quick brown";
> $a =~ /[^ ]/;
> print (length($`));


Try that with

   $a = ' ';

and then with 

   $a = 'x';

You must ensure that the match _succeeded_ before relying on
the value of $`


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Sat, 06 Oct 2007 08:56:03 +0200
From: Larry <dontmewithme@got.it>
Subject: Re: passing $fd as a reference
Message-Id: <dontmewithme-71AB77.08560206102007@news.tin.it>

In article <051020071302388074%jgibson@mail.arc.nasa.gov>,
 Jim Gibson <jgibson@mail.arc.nasa.gov> wrote:

> Use IO::File (untested):
> 
> my $fh1 = new IO::File $song;
> die "open: $!" unless defined $fh1;
> $fh1->binmode;
> $c->send_file($fh1);
> $fh1->close;

thanks it worked great!!

yet, now I'd like to pass a socket filedesc:

my $fh1 = IO::Socket::INET->new(PeerAddr => '127.0.0.1',PeerPort => 
'65000',Proto => 'tcp');
syswrite $fh1, "GET /song/$itemnum.mp3 HTTP/1.1".$CRLF.$CRLF;
$c->send_file($fh1);
$fh1->close;

But it won't work...why ??


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

Date: Sat, 06 Oct 2007 10:24:06 -0000
From:  Brian McCauley <nobull67@gmail.com>
Subject: Re: passing $fd as a reference
Message-Id: <1191666246.122474.313690@50g2000hsm.googlegroups.com>

On Oct 6, 7:56 am, Larry <dontmewit...@got.it> wrote:
> In article <051020071302388074%jgib...@mail.arc.nasa.gov>,
>  Jim Gibson <jgib...@mail.arc.nasa.gov> wrote:
>
> > Use IO::File (untested):
>
> > my $fh1 = new IO::File $song;
> > die "open: $!" unless defined $fh1;
> > $fh1->binmode;
> > $c->send_file($fh1);
> > $fh1->close;
>
> thanks it worked great!!
>
> yet, now I'd like to pass a socket filedesc:
>
> my $fh1 = IO::Socket::INET->new(PeerAddr => '127.0.0.1',PeerPort =>
> '65000',Proto => 'tcp');
> syswrite $fh1, "GET /song/$itemnum.mp3 HTTP/1.1".$CRLF.$CRLF;
> $c->send_file($fh1);
> $fh1->close;
>
> But it won't work...why ??

In what way does it not work?

BTW, this has nothing to do with your question (although  may be
related to your real problem) but is looks like you are trying to
implement an HTTP/1.1 client.

This is a far from simple exercise.  For example HTTP/1.1 clients MUST
support "chunked". Does yours?

Your HTTP request is invalid - it has a 1.1 protocol version number
but lacks the required "Host:" header.

If you want an HTTP client, use LWP (or an external binary).



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

Date: Sat, 06 Oct 2007 10:51:08 -0000
From:  Brian McCauley <nobull67@gmail.com>
Subject: Re: perl join on a non printable variable character ?
Message-Id: <1191667868.600820.81950@50g2000hsm.googlegroups.com>

On Oct 5, 2:14 am, "John W. Krahn" <du...@example.com> wrote:

> You are passing the string '\034' to your program from the command line so
> your $delimiter variable will contain the string consisting of the four
> characters '\', '0', '3' and '4'.

So, the OP is probably really trying to get around to asking...

FAQ: How do I unescape a string?



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

Date: Sat, 06 Oct 2007 01:31:01 +0100
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: SIG{'PIPE'}
Message-Id: <6eCdnWWGIK3TSpvanZ2dnUVZ8v3inZ2d@pipex.net>

Petr Vileta wrote:
>>
> I checked my script and log written by script and I thing this is not a 
> reason. I use pipe only for send data to sendmail and this work already.

    Well, it can fail - you send a larger message than you expect because of 
a bug/problem elsewhere in the program and sendmail fills up the disk or 
reaches its size limit.


-- 
              Just because I've written it doesn't mean that
                   either you or I have to believe it.


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

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


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

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

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

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

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


------------------------------
End of Perl-Users Digest V11 Issue 911
**************************************


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