[24974] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7224 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 8 14:07:37 2004

Date: Fri, 8 Oct 2004 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)

Perl-Users Digest           Fri, 8 Oct 2004     Volume: 10 Number: 7224

Today's topics:
        $!{EINPROGRESS} ???? <karlUNDERSCOREkramsch@yahooPERIODcom.invalid>
    Re: $!{EINPROGRESS} ???? <mritty@gmail.com>
    Re: $!{EINPROGRESS} ???? <matternc@comcast.net>
        [newbie] How can I catch a C comment with a regex? (Belbo)
    Re: [newbie] How can I catch a C comment with a regex? <mritty@gmail.com>
    Re: [newbie] How can I catch a C comment with a regex? <jurgenex@hotmail.com>
        Accessing hashes and converting into an array (Rohit S)
    Re: Accessing hashes and converting into an array <mritty@gmail.com>
    Re: Accessing hashes and converting into an array <1usa@llenroc.ude.invalid>
    Re: Accessing hashes and converting into an array ctcgag@hotmail.com
    Re: any tools to enable test automation for scripting l <comdog@panix.com>
    Re: any tools to enable test automation for scripting l <shawn.corey@sympatico.ca>
        Help required in accessing hash references. (Rohit S)
    Re: Help required in accessing hash references. <tadmc@augustmail.com>
    Re: How to flush a stinkin' socket? (J. Romano)
    Re: How to flush a stinkin' socket? <lawshouse.public@btconnect.com>
    Re: How to prevent the removal of \ from pairs of \\? <bigal187@invalid.rx.eastcoasttfc.com>
    Re: linked list for string class (Anno Siegel)
    Re: To Tad: Great perl class, and question <comdog@panix.com>
    Re: Top 10 list algorithm ctcgag@hotmail.com
    Re: Top 10 list algorithm ctcgag@hotmail.com
    Re: Using a variable size with the repetition quantifie (Philippe Aymer)
    Re: Using a variable size with the repetition quantifie <pinyaj@rpi.edu>
    Re: Using a variable size with the repetition quantifie <nobull@mail.com>
    Re: Using a variable size with the repetition quantifie (Charles DeRykus)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 8 Oct 2004 14:19:49 +0000 (UTC)
From: KKramsch <karlUNDERSCOREkramsch@yahooPERIODcom.invalid>
Subject: $!{EINPROGRESS} ????
Message-Id: <ck67m5$g3h$1@reader2.panix.com>




  In IO/Socket.pm is find things like $!{EINPROGRESS}, suggesting that
$! is a hash.  But in perlvar there's no indication of this:

       $OS_ERROR
       $ERRNO
       $!      If used numerically, yields the current value of
               the C "errno" variable, with all the usual
               caveats.  (This means that you shouldn't depend on
               the value of $! to be anything in particular
               unless you've gotten a specific error return indi­
               cating a system error.)  If used an a string,
               yields the corresponding system error string.  You
               can assign a number to $! to set errno if, for
               instance, you want "$!" to return the string for
               error n, or you want to set the exit value for the
               die() operator.  (Mnemonic: What just went bang?)

               Also see "Error Indicators".

  What gives?

  Thanks!

	Karl

-- 
Sent from a spam-bucket account; I check it once in a blue moon.  If
you still want to e-mail me, cut out the extension from my address,
and make the obvious substitutions on what's left.


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

Date: Fri, 08 Oct 2004 14:25:26 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: $!{EINPROGRESS} ????
Message-Id: <qrx9d.29$uN4.14@trndny05>

"KKramsch" <karlUNDERSCOREkramsch@yahooPERIODcom.invalid> wrote in
message news:ck67m5$g3h$1@reader2.panix.com...
>   In IO/Socket.pm is find things like $!{EINPROGRESS}, suggesting that
> $! is a hash.  But in perlvar there's no indication of this:
>
<snip>

>   What gives?

The code in question use's Errno.  If you looked at the code for Errno,
you would find the following:
(from:
http://search.cpan.org/~nwclark/perl-5.8.5/ext/Errno/Errno_pm.PL )

 Errno also makes %! magic such that each element of %! has a non-zero
value only if $! is set to that value.

Paul Lalli




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

Date: Fri, 08 Oct 2004 11:20:49 -0400
From: Chris Mattern <matternc@comcast.net>
Subject: Re: $!{EINPROGRESS} ????
Message-Id: <b9-dnTbZY6DMLfvcRVn-vA@comcast.com>

KKramsch wrote:

> 
> 
> 
>   In IO/Socket.pm is find things like $!{EINPROGRESS}, suggesting that
> $! is a hash.  

It's not.  Of course it's not.  It can't be.  $whatever can only be a
scalar.  But %! is a hash, and it'll be accessed by saying 
$!{$someindex}.

> But in perlvar there's no indication of this: 
> 
>        $OS_ERROR
>        $ERRNO
>        $!      If used numerically, yields the current value of
>                the C "errno" variable, with all the usual
>                caveats.  (This means that you shouldn't depend on
>                the value of $! to be anything in particular
>                unless you've gotten a specific error return indi­
>                cating a system error.)  If used an a string,
>                yields the corresponding system error string.  You
>                can assign a number to $! to set errno if, for
>                instance, you want "$!" to return the string for
>                error n, or you want to set the exit value for the
>                die() operator.  (Mnemonic: What just went bang?)
> 
>                Also see "Error Indicators".
> 
>   What gives?

Perhaps looking up the variable you're actually dealing with
would've helped.  It was right under $!...

 %!      Each element of "%!" has a true value only if $! is
             set to that value.  For example, $!{ENOENT} is true
             if and only if the current value of $! is "ENOENT";
             that is, if the most recent error was "No such file
             or directory" (or its moral equivalent: not all
             operating systems give that exact error, and
             certainly not all languages).  To check if a
             particular key is meaningful on your system, use
             "exists $!{the_key}"; for a list of legal keys, use
             "keys %!".  See Errno for more information, and also
             see above for the validity of $!.

> 
>   Thanks!
> 
> Karl
> 

-- 
             Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"


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

Date: 8 Oct 2004 09:30:18 -0700
From: ba11ard66@hotmail.com (Belbo)
Subject: [newbie] How can I catch a C comment with a regex?
Message-Id: <295a92eb.0410080830.517d16cd@posting.google.com>

Hi,
I've tried to catch C comments (/* ... */) with a cycle like this:

	while(($comm =~ /\/\*/) and
	  ($comm !~ /\*\//) and
	  (defined($next_line=<IN_FICH>)))
	     {$comm=$comm.$next_line;}
	print $comm

I'm sure there's an another way less stupid. But what?

Bye


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

Date: Fri, 08 Oct 2004 16:37:45 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: [newbie] How can I catch a C comment with a regex?
Message-Id: <tnz9d.140$gI6.2@trndny09>

"Belbo" <ba11ard66@hotmail.com> wrote in message
news:295a92eb.0410080830.517d16cd@posting.google.com...
> Hi,
> I've tried to catch C comments (/* ... */) with a cycle like this:
>
> while(($comm =~ /\/\*/) and
>   ($comm !~ /\*\//) and
>   (defined($next_line=<IN_FICH>)))
>      {$comm=$comm.$next_line;}
> print $comm
>
> I'm sure there's an another way less stupid. But what?

I have no idea by what criteria you're defining stupidity in this case.
Regardless:

Please check the Perl FAQ *before* posting to this group:
perldoc -q comment

Paul Lalli






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

Date: Fri, 08 Oct 2004 17:05:16 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: [newbie] How can I catch a C comment with a regex?
Message-Id: <gNz9d.49$gd1.32@trnddc08>

Belbo wrote:
> Hi,
> I've tried to catch C comments (/* ... */) with a cycle like this:

[Attempt at parsing a programming language using REs snipped]

You don't. Programming langauges are too complex to be parsed by REs.
Just one issue (the most trivial one) that apparently you didn't think 
about: What if the /* appears inside of text?

> I'm sure there's an another way less stupid. But what?

Use a parser to parse a programming language.

jue 




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

Date: 8 Oct 2004 07:26:17 -0700
From: rohit.satabhai@bt.com (Rohit S)
Subject: Accessing hashes and converting into an array
Message-Id: <2bbc95a4.0410080626.43eeca6f@posting.google.com>

==========================================================================
 Using DBI Perl Programming I get a database o/p as
 below
 Student             SubjectCode        Marks
 ------------------------------------------------
 A                       Ma                90
 A                       Sc                89
 B                       Ma                70
 B                       Sc                71
 B                       Ge                71
 C                       Sc                73
 C                       Ge                97
 ...                    ...                ...
 -------------------------------------------------
 Subject code may vary to any value.
 I need a report o/p in the following format and
 displayed in HTML
 Student            Ma  Sc  Ge .....
 ------------------------------------------------
 A                  90  89 
 B                  70  71  71
 C                      73  97
 -------------------------------------------------


  # chuck all the data into an array
    my $students;
    while (my $row = $sth->fetchrow_hashref) {
    $students->{$row->{$student}}->{$row->{$subject}} = $row->{$mark};


    foreach $student(sort keys %$students) {
    print $student, "\t";
    foreach  $subject(sort keys %{$students->{$student}}) {
        print "\t", $students->{$student}->{$subject};
    }
    print "\n";
 }


================================================================
The subject field would vary
But this doesnt seem to work.I also need to put the values in an matrix.

Could anyone pls help me out in this.

Regards
Rohit


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

Date: Fri, 08 Oct 2004 14:39:35 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Accessing hashes and converting into an array
Message-Id: <HEx9d.24$wV4.14@trndny03>

"Rohit S" <rohit.satabhai@bt.com> wrote
in message news:2bbc95a4.0410080626.43eeca6f@posting.google.com...
AND in message news:2bbc95a4.0410080623.451ea949@posting.google.com...

Please don't do that.  Post once.  And for damned sure don't change
subjects.


>   # chuck all the data into an array
>     my $students;
>     while (my $row = $sth->fetchrow_hashref) {
>     $students->{$row->{$student}}->{$row->{$subject}} = $row->{$mark};

Is there some reason you don't have your while loop being ended?
Please post real code.  Have you seen the guidelines that are posted
here frequently?

>     foreach $student(sort keys %$students) {
>     print $student, "\t";
>     foreach  $subject(sort keys %{$students->{$student}}) {
>         print "\t", $students->{$student}->{$subject};
>     }
>     print "\n";
>  }
>
>
> ================================================================
> The subject field would vary
> But this doesnt seem to work.I also need to put the values in an
matrix.

"Doesn't Work" is an absolutely abhorrent phrase.  It tells us
absolutely nothing.  How did it not work?  What were you expecting, and
in what way did the results differ?  Have you seen the guidelines that
are posted here frequently?

> Could anyone pls help me out in this.

The following quick script, based on your code above (modified to
populate with dummy data and make it strict compliant only), works fine
for me.

#!/usr/bin/perl
use strict;
use warnings;

my $students;

$students->{Paul}->{CS1} = 95;
$students->{Paul}->{Math} = 90;
$students->{Paul}->{Phil} = 100;
$students->{Justin}->{CS1} = 85;
$students->{Justin}->{Math} = 80;
$students->{Justin}->{Phil} = 70;

foreach my $student(sort keys %$students) {
  print $student, "\t";
  foreach  my $subject(sort keys %{$students->{$student}}) {
    print "\t", $students->{$student}->{$subject};
  }
  print "\n";
}
__END__
Justin          85      80      70
Paul            95      90      100

I surmise then, that the problem is with how you are either storing the
data in your database or with how you are retrieving it.

So here's a huge hint:  Make your script strict-compliant.  Add use
strict; to the beginning of your script.  Declare your variables.  You
should almost immediately see the problem with how you are retrieving
your data.

Paul Lalli




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

Date: 8 Oct 2004 15:42:58 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Accessing hashes and converting into an array
Message-Id: <Xns957C772EC21D2asu1cornelledu@132.236.56.8>

rohit.satabhai@bt.com (Rohit S) wrote in
news:2bbc95a4.0410080626.43eeca6f@posting.google.com: 

Don't post the same message repeatedly (and with different subject lines 
at that).

>  Using DBI Perl Programming I get a database o/p as

What is o/p?

>  below
>  Student             SubjectCode        Marks
>  ------------------------------------------------
>  A                       Ma                90
>  A                       Sc                89
>  B                       Ma                70
>  B                       Sc                71
>  B                       Ge                71
>  C                       Sc                73
>  C                       Ge                97
>  ...                    ...                ...
>  -------------------------------------------------
>  Subject code may vary to any value.

>  I need a report o/p in the following format and
>  displayed in HTML

What is o/p?

>  Student            Ma  Sc  Ge .....
>  ------------------------------------------------
>  A                  90  89 
>  B                  70  71  71
>  C                      73  97
>  -------------------------------------------------
> 
> 
>   # chuck all the data into an array
>     my $students;
>     while (my $row = $sth->fetchrow_hashref) {
>     $students->{$row->{$student}}->{$row->{$subject}} = $row->{$mark};
> 
> 
>     foreach $student(sort keys %$students) {
>     print $student, "\t";
>     foreach  $subject(sort keys %{$students->{$student}}) {
>         print "\t", $students->{$student}->{$subject};
>     }
>     print "\n";
>  }

Huh? Post code others can run.

> The subject field would vary
> But this doesnt seem to work.

Define "work".

> I also need to put the values in an matrix. 

And what does that mean?
 
> Could anyone pls help me out in this.

I am going to suggest reading the posting guidelines for this group.

#! perl

use strict;
use warnings;

use DBI;

my $dir = $ENV{TMP};
$dir =~ s{\\}{/}g;

my $dbh = DBI->connect("DBI:CSV:f_dir=$dir")
    or die "Cannot connect: @{[$DBI::errstr]}";


my $sth = $dbh->prepare(qq{
    CREATE TABLE a (
    student CHAR(1), 
    subject CHAR(2), 
    marks INTEGER
    )}
) or die "Cannot prepare: @{[$dbh->errstr]}";

$sth->execute or die "Cannot execute: @{[$sth->errstr]}";

while(<DATA>) {
    my ($student, $subject, $marks) = split;

    $dbh->do("INSERT INTO a VALUES ( 
        @{[$dbh->quote($student)]},
        @{[$dbh->quote($subject)]}, 
        $marks)"
    );
}

$sth = $dbh->prepare("SELECT * from a");
$sth->execute or die "Cannot execute: @{[$sth->errstr]}";

my $students = {};

while(my $row = $sth->fetchrow_hashref) {
    $students->{$row->{student}}->{$row->{subject}}->{marks} = $row->
{marks};
}

for my $student (sort {$a cmp $b} keys %{$students}) {
    print "$student\t";
    for my $subject (sort {$a cmp $b} keys %{$students->{$student}}) {
        print $students->{$student}->{$subject}->{marks}."\t";
    }
    print "\n";
}        

$sth->finish;
$dbh->disconnect;

__DATA__
A Ma 90
A Sc 89
B Ma 70
B Sc 71
B Ge 71
C Sc 73
C Ge 97


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

Date: 08 Oct 2004 17:15:16 GMT
From: ctcgag@hotmail.com
Subject: Re: Accessing hashes and converting into an array
Message-Id: <20041008131516.982$Ht@newsreader.com>

rohit.satabhai@bt.com (Rohit S) wrote:
> =========================================================================
> =
>  Using DBI Perl Programming I get a database o/p as
>  below
>  Student             SubjectCode        Marks
>  ------------------------------------------------
>  A                       Ma                90
>  A                       Sc                89
>  B                       Ma                70
>  B                       Sc                71
>  B                       Ge                71
>  C                       Sc                73
>  C                       Ge                97
>  ...                    ...                ...
>  -------------------------------------------------
>  Subject code may vary to any value.
>  I need a report o/p in the following format and
>  displayed in HTML

What is o/p?

>  Student            Ma  Sc  Ge .....
>  ------------------------------------------------
>  A                  90  89
>  B                  70  71  71
>  C                      73  97
>  -------------------------------------------------
>
>   # chuck all the data into an array

What array would that be?

>     my $students;
>     while (my $row = $sth->fetchrow_hashref) {
>     $students->{$row->{$student}}->{$row->{$subject}} = $row->{$mark};

You didn't close the loop, nor did you indent properly.

You may want to keep track of all actually occuring courses:
      $seen{$row->{$subject}}++;
}


>     foreach $student(sort keys %$students) {
>     print $student, "\t";
>     foreach  $subject(sort keys %{$students->{$student}}) {

## You want all the subjects to line up under each other, so:
      foreach  $subject(sort keys %seen) {
##  (of course, you should reall sort once, store in array)

>         print "\t", $students->{$student}->{$subject};
>     }
>     print "\n";
>  }
>


Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Fri, 08 Oct 2004 11:11:50 -0500
From: brian d foy <comdog@panix.com>
To: ty_li@yahoo.com (matt)
Subject: Re: any tools to enable test automation for scripting language like perl?
Message-Id: <081020041111505080%comdog@panix.com>

[[ This message was both posted and mailed: see
   the "To," "Cc," and "Newsgroups" headers for details. ]]

In article <10ca4b4a.0410080445.5a72a00c@posting.google.com>, matt
<ty_li@yahoo.com> wrote:

> hi all:
> I am working on a script language very similiar to Perl. It is really
> cool if I can automate the test. is there any automatic test tools
> around?

You could use Test::Harness to write a testing tool.  Your tests,
even if they are in another language, just have to use the interface
that Test::Harness expects: printing "ok" or "not ok".  I think
Andy Lester may have written an article about this somewhere.


Beyond that, I would need to know more about what you are doing.
Most things are possible though :)

-- 
brian d foy, comdog@panix.com


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

Date: Fri, 08 Oct 2004 09:05:29 -0400
From: Shawn Corey <shawn.corey@sympatico.ca>
Subject: Re: any tools to enable test automation for scripting language like perl?
Message-Id: <mfw9d.32492$jj2.1376150@news20.bellglobal.com>

matt wrote:
> I am working on a script language very similiar to Perl.

Why? More specifically, what abilities or features will this language 
have that Perl does not? Does it combine Perl's nifty features with 
another language's? Aside from being an intellectual exercise, why bother?

	--- Shawn


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

Date: 8 Oct 2004 07:23:28 -0700
From: rohit.satabhai@bt.com (Rohit S)
Subject: Help required in accessing hash references.
Message-Id: <2bbc95a4.0410080623.451ea949@posting.google.com>

==========================================================================
 Using DBI Perl Programming I get a database o/p as
 below
 Student             SubjectCode        Marks
 ------------------------------------------------
 A                       Ma                90
 A                       Sc                89
 B                       Ma                70
 B                       Sc                71
 B                       Ge                71
 C                       Sc                73
 C                       Ge                97
 ...                    ...                ...
 -------------------------------------------------
 Subject code may vary to any value.
 I need a report o/p in the following format and
 displayed in HTML
 Student            Ma  Sc  Ge .....
 ------------------------------------------------
 A                  90  89 
 B                  70  71  71
 C                      73  97
 -------------------------------------------------


  # chuck all the data into an array
    my $students;
    while (my $row = $sth->fetchrow_hashref) {
    $students->{$row->{$student}}->{$row->{$subject}} = $row->{$mark};


    foreach $student(sort keys %$students) {
    print $student, "\t";
    foreach  $subject(sort keys %{$students->{$student}}) {
        print "\t", $students->{$student}->{$subject};
    }
    print "\n";
 }


================================================================
The subject field would vary
But this doesnt seem to work.I also need to put the values in an matrix.

Could anyone pls help me out in this.

Regards
Rohit


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

Date: Fri, 8 Oct 2004 10:18:16 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Help required in accessing hash references.
Message-Id: <slrncmdbto.21a.tadmc@magna.augustmail.com>

Rohit S <rohit.satabhai@bt.com> wrote:

>     my $students;
>     while (my $row = $sth->fetchrow_hashref) {
>     $students->{$row->{$student}}->{$row->{$subject}} = $row->{$mark};


You should always enable warnings and strictures when developing Perl code!

What are the values in the $student, $subject and $mark variables?

Maybe those are supposed to be hash keys from your query rather
than variables?  (eg: $students->{$row->{student}} ...)


> But this doesnt seem to work.


What does it do?

What do you want it to do instead?

Have you seen the Posting Guidelines that are posted here frequently?


> Could anyone pls help me out in this.


If you post a short and complete program that we can run, I am sure
that someone can solve your problem.

Without that we can only guess...


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


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

Date: 8 Oct 2004 07:28:03 -0700
From: jl_post@hotmail.com (J. Romano)
Subject: Re: How to flush a stinkin' socket?
Message-Id: <b893f5d4.0410080628.7ae74bca@posting.google.com>

hik2sanity@hotmail.com (your name here) wrote in message news:<a794b8d.0410040453.67a3bda5@posting.google.com>...
>
> You may be familar with the following code snippet as it was taken
> from some posts in this group. However, whatever I do, I cannot get
> this message through the socket immediately which causes the other
> side to determine I am in trouble because it hasn't received a health
> check. The message finally shows up after I issue the shutdown
> command, which is unacceptable. Any ideas? Windows peculiarity?

Dear Your Name Here,

   I had a similar problem about a year ago, and it looks like your
problem might be due to that same issue.

   A good way to check whether or not your Perl script is working is
to write a receiving script to run alongside your connector script and
see if they are able to talk to each other.  I modified your script
slightly and included another script, called "conn.pl" and "rec.pl",
respectively.  Here thy are (more follows after the scripts):


#!/usr/bin/perl
# File: conn.pl

use strict;
use warnings;
use IO::Socket;

my $msg = "Take me to your leader";

my $conn = IO::Socket::INET->new( PeerAddr => '127.0.0.1', 
                                  PeerPort => '8089', 
                                  Proto  => 'tcp');

die "Cannot connect: $!\n" unless $conn;
$conn->autoflush(1);
$conn->print($msg);

sleep 100;

print "Program $0 has ended.\n";

__END__



#!/usr/bin/perl
# File: rec.pl

use strict;
use warnings;
use IO::Socket;

my $localPort = 8089;

print "Attempting to connect as server...\n";
my $server = IO::Socket::INET->new(LocalPort => $localPort,
                                   Proto => "tcp",
                                   Reuse => 1,
                                   Listen => 1)
   or die "\nCouldn't be a server on port $localPort: $!\n";

my $socket = $server->accept();

print "Got a connection!\n";

while (<$socket>)
{
   print "Received: $_\n";
}

__END__


   Now create those files in the same directory and open two command
windows (and change the directory of both to the directory you saved
them to).  Now start both scripts (start the rec.pl script a few
seconds before the conn.pl script).

   You will notice that the rec.pl script says that it "Got a
connection!" yet nothing is ever printed until you hit CTRL-C in the
conn.pl script.  This looks like the behavior you were talking about
(in that nothing gets sent until the connection shuts down).

   The information DOES get sent, but the problem lies with the
receiving script (rec.pl), not with the connector script (conn.pl). 
The reason nothing ever gets printed out (until the conn.pl script is
shut down) is because the "while (<$socket>)" code keeps reading the
socket for characters until it encounters a newline character (or
until the connection is terminated, whichever comes first).  It keeps
reading until it hits a newline because a newline is what's stored in
the $/ variable (read about this variable in "perldoc perlvar" to find
out more about it).

   Therefore, to fix this problem, you can do one of two things. 
Either change the string in conn.pl to end with a newline, like this:

      my $msg = "Take me to your leader\n";

or add the line:

      $/ = \1;

right before the while loop in the rec.pl script.  That line
(according to "perldoc perlvar") makes the "<$socket>" code in the
while condition return every character (instead of every line that's
terminated with a newline).

   Note that if you take the second approach, then the while-loop will
loop through every letter, and you'll get output like:

Received: T
Received: a
Received: k
Received: e
Received:
Received: m
Received: e
Received:
Received: t
Received: o
 .
 .
 .

which may not be what you want.

   In summary, the problem is not with your original Perl script, but
rather with the program that reads the data from the socket.  It
receives the data just fine, but it refuses to do anything with it
until some condition is met (like it encounters a newline, or it fills
its buffer, or maybe for some other reason).  Since you didn't post
the code of your receiving program I can't examine it, and so I can't
really say why it won't process the data.  (If I were to guess, I'd
say it's because there was no newline character in the data you sent
it.)

   I hope this helps.

   -- Jean-Luc


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

Date: Fri, 08 Oct 2004 15:46:13 +0100
From: Henry Law <lawshouse.public@btconnect.com>
Subject: Re: How to flush a stinkin' socket?
Message-Id: <hu9dm01jh4olgr9b75rqsg3lnai7h8st1q@4ax.com>

On 8 Oct 2004 07:28:03 -0700, jl_post@hotmail.com (J. Romano) wrote:


>Dear Your Name Here,
>
>   I had a similar problem about a year ago, and it looks like your
>problem might be due to that same issue.

I've no idea whether or not this post answers the question (sounds
plausible to me ...) but I had to post my admiration at such a
comprehensively helpful and beautifully written response.  Worth a
virtual cup of coffee, maybe even a virtual beer!

Henry Law       <><     Manchester, England 


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

Date: Fri, 8 Oct 2004 07:04:24 -0700
From: "187" <bigal187@invalid.rx.eastcoasttfc.com>
Subject: Re: How to prevent the removal of \ from pairs of \\?
Message-Id: <2snl3aF1n0qb1U1@uni-berlin.de>

Abigail wrote:
> Tad McClellan (tadmc@augustmail.com) wrote on MMMMLV September
> MCMXCIII in <URL:news:slrncmajk3.akq.tadmc@magna.augustmail.com>:
>>>  Bernie Cosell <bernie@fantasyfarm.com> wrote:
>>>> Uri Guttman <uri@stemsystems.com> wrote:
>>>>
>>>> } >>>>> "PL" == Paul Lalli <mritty@gmail.com> writes:
>>>>
>>>> }   PL> Note that I don't especially understand why this works.
>>>> Why would }   PL> single-quoted heredocs not work the same as
>>>> 'normal' single-quoted }   PL> strings?
>>>> }
>>>> } because in single quoted strings \ is needed to escape ' and \.
>>>
>>>
>>>> Why does that apply if you use 'q' with an explicit terminator?
>>>
>>>
>>>  For the same reason as when using single quotes, to escape the
>>> terminator.
>>>
>>>
>>>> Is there a need to scan for '\' if
>>>> I'm doing:  q{stuff} ?
>>>
>>>
>>>  Yes, as you might need a
>>>
>>>     \}
>>>
>>>  in there somewhere.
>
>
> Or a \{


Or a \\




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

Date: 8 Oct 2004 13:12:44 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: linked list for string class
Message-Id: <ck63oc$na$1@mamenchi.zrz.TU-Berlin.DE>

 <larry_wallet@yahoo.com> wrote in comp.lang.perl.misc:
> How would I go about creating a linked list in Perl?  I would like to
> dynamically generate structures or objects and link one to the next so
> that I may traverse the list back and forth.
> 
> I would then like to have each object in the list contain as a member
> a single text character.  By stringing together an arbitrary number of
> these objects, this larger structure, which could be a class
> containing the linked list, could be used as a "string" class,
> literally a string of characters, not bound by the limitations of
> simple common strings.

I'm not happy with your terminology here.  How can "this ... structure"
(a linked list) be a class?  How can it "contain the linked list"
which would be itself?  It doesn't make sense.

> I appreciate any thoughts on how I might implement this structure in
> Perl, which seems uniquely well suited to the task.

What you want is trivial to implement in Perl (see below), but
the advantages over plain arrays or strings escape me.  There
isn't much you can do with a liked list that can't be done with
the more traditional structures.  If you want characters who know
which string they are part of (inherently true for list nodes),
that could be implemented in other ways too.

Anyway, below is the skeleton of a node class that could be embellished
to base linked list on.  The pay load of each node can be any scalar,
not just characters.

Anno

#!/usr/local/bin/perl
use strict; use warnings; $| = 1;

my $n;
$n = Node->new( $_, $n) for qw( alpha beta gamma delta);
print "$_\n" for $n->list;

###################################################################

package Node;

# create new node. if $tail is given, append it to the new node
sub new {
    my ( $class, $data, $tail) = @_;
    bless [ $data, $tail], $class;
}

# return a list of the data contents of all nodes
sub list {
    my $node = shift;
    return ( $node->[ 0]) unless $node->[ 1];
    ( $node->[ 0], $node->[ 1]->list);
}



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

Date: Fri, 08 Oct 2004 11:07:16 -0500
From: brian d foy <comdog@panix.com>
To: "asdfasd" <af4bh@iglou.com>
Subject: Re: To Tad: Great perl class, and question
Message-Id: <081020041107168603%comdog@panix.com>

[[ This message was both posted and mailed: see
   the "To," "Cc," and "Newsgroups" headers for details. ]]

In article <41661b40$1_1@news.iglou.com>, asdfasd <af4bh@iglou.com>
wrote:

> Thanks Tad.  I enjoy your training class a lot during your visit here in
> Lexington, Kentucky.

> Is there a tool, or some scripts, that will be able to parse the source
> files and "suggest" the existance of local/global variable conflicts?  We
> are trying to upgrade our perl runtime (Windows) to 5.8x, but facing the
> possibility of having an extensive code review.  Any help will be greatly
> appreciated.


I've found that most places should probably leave existing code as
it is until they *need* to change it.  If it works now, anything you
do to it can break it in new ways.  I recommend using your new coding
skills for new projects.

That being said, there are a lot of tools in the Devel:: namespace
to do various sorts of inspections.  Human eyeballs tend to be the
best tool, in my experience. :)

-- 
brian d foy, comdog@panix.com
Just another Stonehenge instructor, http://www.stonehenge.com


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

Date: 08 Oct 2004 15:31:48 GMT
From: ctcgag@hotmail.com
Subject: Re: Top 10 list algorithm
Message-Id: <20041008113148.638$4K@newsreader.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> John Bokma  <postmaster@castleamber.com> wrote in comp.lang.perl.misc:
> > anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in
> > news:ck3pi4$d62$1@mamenchi.zrz.TU-Berlin.DE:
> >
> > > John Bokma  <postmaster@castleamber.com> wrote in
> > > comp.lang.perl.misc:
> >
> > [ insertion sort ]
> >
> > > It is not a good general-purpose sorting algorithm because insertion
> > > means you must move n/2 elements on average to make room for a new
> > > one, so the insertions alone make it an n**2 process.
> >
> > Depends on your datastructure of course.
>
> In general, yes.  In this case, we want a compact list (at least of
> pointers) to perform a binary search on.
>
> > > On the other hand, if you must *keep* a list sorted while adding and
> > > removing elements, it is practically your only choice.  In this
> > > particular case it isn't so bad because the list of top-k candidates
> > > is short and remains short.
> >
> > Bubble sort might out perform normal quicksort if k is small, I guess.
>
> Well, bubble sort avoids the overhead of insertion, it swaps elements.

Bubble sort does insertion by swapping elements.  Which is a pretty aweful
way to do insertion.  Especially when insertion is supported with very low
(even hardware-level) optimizations.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 08 Oct 2004 15:40:21 GMT
From: ctcgag@hotmail.com
Subject: Re: Top 10 list algorithm
Message-Id: <20041008114021.918$L2@newsreader.com>

Fatted <fatted@gmail.com> wrote:
> Is there a better (faster) way of implementing my top_sort function?
> (Creating a top 10 list of the highest numbers from a large set).
> Or did I get lucky? :)

Your appear to be operating with a set of 10_000 numbers.  In my book,
that is a couple orders of magnitude below "large".

For 10,000, I wouldn't even bother with anything except

@top10 = (sort {whatever} @data)[0..9];


> --
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my @top10 = (0,0,0,0,0,0,0,0,0,0);

What if some of the top10 numbers are negative?

>
> for(my $i = 0;$i < 10000; $i++)
> {
>          my $num = rand();
>          @top10 = @{top_sort(\@top10, $num)};

Invoking the overhead of a subroutine call for reach member of the set
is going to kill your performance.  If you are really worried about
performance, you should batch up your numbers.

>
>          for(my $i = 0; $i < $#$array; ++$i)

$i < @$array
or
$i<=$#$array


Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 8 Oct 2004 07:48:10 -0700
From: aymerphilippe@hotmail.com (Philippe Aymer)
Subject: Re: Using a variable size with the repetition quantifier
Message-Id: <47971ff0.0410080648.782b2395@posting.google.com>

Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote in message news:<Pine.SOL.3.96.1041007165936.20047A-100000@vcmr-86.server.rpi.edu>...
> On 7 Oct 2004, Philippe Aymer wrote:
> 
> >I'm looking at a PERL regex (if possible) that will be able to use a
> >repetition quantifier metachar, but the number of repetition is
> >unknown until runtime.
> >For example:
> >
> >X3xyz...
> >
> >the number 3 give me the number of "repetition" for the next chars
> >(length of string), something like:
> >
> >/X(\d)(\w{\1})/
> >
> >but \1 is not possible within {} the repetition quantifier.
> >
> >Is there a way to use {} with the repetition number only known from
> >the regex ?
> 
> Not exactly.  You have to do it by some other means.  Here are two
> examples:
> 
>   $str =~ /X(\d)/g and $str =~ /\G(\w{$1})/
> 
> and
> 
>   $str =~ /X(\d)((??{ "\\w{$1}" }))/

This looks like a good solution if there is nothing after in the
string... But in my case, my regex is longer. I should have give this
info before =(

So for example:

X3xyzA4abc....

and only the number can give me the length of the string I want to
grab.

Thanks again,

Phil.


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

Date: Fri, 8 Oct 2004 12:51:01 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: Using a variable size with the repetition quantifier
Message-Id: <Pine.SOL.3.96.1041008124939.2144B-100000@vcmr-86.server.rpi.edu>

On 8 Oct 2004, Philippe Aymer wrote:

>>   $str =~ /X(\d)((??{ "\\w{$1}" }))/
>
>This looks like a good solution if there is nothing after in the
>string... But in my case, my regex is longer. I should have give this
>info before =(
>
>So for example:
>
>X3xyzA4abc....
>
>and only the number can give me the length of the string I want to
>grab.

I don't think you actually tried my solution, then.

  $str = "X3xyzA4abc";
  $str =~ /X(\d)((??{ "\\w{$1}" }))/
    and print "$1 -> '$2'\n";

That prints:  3 -> 'xyz'

--
Jeff "japhy" Pinyan         %  How can we ever be the sold short or
RPI Acacia Brother #734     %  the cheated, we who for every service
  Senior Dean, Fall 2004    %  have long ago been overpaid?
RPI Corporation Secretary   %
http://japhy.perlmonk.org/  %    -- Meister Eckhart




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

Date: Fri, 08 Oct 2004 17:58:46 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Using a variable size with the repetition quantifier
Message-Id: <ck6gnl$dj7$1@sun3.bham.ac.uk>

Philippe Aymer wrote:

> Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote in message news:<Pine.SOL.3.96.1041007165936.20047A-100000@vcmr-86.server.rpi.edu>...
> 
>>On 7 Oct 2004, Philippe Aymer wrote:
>>>
>>>/X(\d)(\w{\1})/
>>>
>>>but \1 is not possible within {} the repetition quantifier.
>>
>>  $str =~ /X(\d)/g and $str =~ /\G(\w{$1})/
>>
>>  $str =~ /X(\d)((??{ "\\w{$1}" }))/
> 
> This looks like a good solution if there is nothing after in the
> string... But in my case, my regex is longer.

Can you explain why you think this is a problem?



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

Date: Fri, 8 Oct 2004 17:12:08 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Using a variable size with the repetition quantifier
Message-Id: <I59zs8.D68@news.boeing.com>

In article <47971ff0.0410080648.782b2395@posting.google.com>,
Philippe Aymer <aymerphilippe@hotmail.com> wrote:
>Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote in message news:<Pine.SOL.3.96.1041007165936.20047A-100000@vcmr-86.server.rpi.edu>...
>> On 7 Oct 2004, Philippe Aymer wrote:
>> 
>> >I'm looking at a PERL regex (if possible) that will be able to use a
>> >repetition quantifier metachar, but the number of repetition is
>> >unknown until runtime.
>> >For example:
>> >
>> >X3xyz...
>> >
>> >the number 3 give me the number of "repetition" for the next chars
>> >(length of string), something like:
>> >
>> >/X(\d)(\w{\1})/
>> >
>> >but \1 is not possible within {} the repetition quantifier.
>> >
>> >Is there a way to use {} with the repetition number only known from
>> >the regex ?
>> 
>> Not exactly.  You have to do it by some other means.  Here are two
>> examples:
>> 
>>   $str =~ /X(\d)/g and $str =~ /\G(\w{$1})/
>> 
>> and
>> 
>>   $str =~ /X(\d)((??{ "\\w{$1}" }))/
>
>This looks like a good solution if there is nothing after in the
>string... But in my case, my regex is longer. I should have give this
>info before =(
>
>So for example:
>
>X3xyzA4abc....
>
>and only the number can give me the length of the string I want to
>grab.
>

If you're trying to grab 'em all, maybe:

$str="X3XyzA4abcd....";

print "$2\n" while $str =~/\D*(\d)((??{ "\\w{$1}" }))/g; 


--
Charles DeRykus


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

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 V10 Issue 7224
***************************************


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