[23919] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6121 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 12 06:05:42 2004

Date: Thu, 12 Feb 2004 03:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 12 Feb 2004     Volume: 10 Number: 6121

Today's topics:
    Re: A Newbie Array Problem <gnari@simnet.is>
    Re: compile Perl as a STATIC library <kalinaubears@iinet.net.au>
    Re: Encrypt and Decrypt for text ... <matthew.garrish@sympatico.ca>
    Re: Encrypt and Decrypt for text ... <dwall@fastmail.fm>
    Re: formating pipe delimited file <krahnj@acm.org>
    Re: formating pipe delimited file (Anno Siegel)
        non-aggressive regular expression matching? <jiangchanghao@hotmail.com>
    Re: non-aggressive regular expression matching? <pinyaj@rpi.edu>
    Re: Optimization request (Aaron Sherman)
    Re: Optimization request thumb_42@yahoo.com
        perl 'sendmail' equivalent in windows (KK)
    Re: perl 'sendmail' equivalent in windows <noreply@gunnar.cc>
    Re: perl 'sendmail' equivalent in windows <bernard.el-haginDODGE_THIS@lido-tech.net>
    Re: Perl usage these days? (Mike)
    Re: RFC: utils.pm <tore@aursand.no>
    Re: RFC: utils.pm <uri@stemsystems.com>
    Re: RFC: utils.pm <Joe.Smith@inwap.com>
        Same problem building several modules on XP using Visua <notpublic@restricted.com>
    Re: Search and replace string <ajay_kumarsingh@yahoo.com>
    Re: Search and replace string <noreply@gunnar.cc>
    Re: Search and replace string <gnari@simnet.is>
    Re: Term::Prompt broken? Or am I misreading documentati <wherrera@lynxview.com>
    Re: Using Tie::IxHash order a hash reference <noreply@gunnar.cc>
    Re: Using Tie::IxHash order a hash reference <kevin@vaildc.net>
    Re: Using Tie::IxHash order a hash reference <pinyaj@rpi.edu>
    Re: Using Tie::IxHash order a hash reference <noreply@gunnar.cc>
        When i try to implement a server program giving UDP as  (Tompyna)
    Re: When i try to implement a server program giving UDP thumb_42@yahoo.com
    Re: When i try to implement a server program giving UDP (Anno Siegel)
    Re: When i try to implement a server program giving UDP <gnari@simnet.is>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 12 Feb 2004 08:42:53 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: A Newbie Array Problem
Message-Id: <c0fe8k$t2t$1@news.simnet.is>


"Down Loader" <iamdownloading@yahoo.com> wrote in message
news:402ac67e$1_1@127.0.0.1...
> Tad McClellan <tadmc@augustmail.com> wrote in
> news:slrnc2j8q8.64f.tadmc@magna.augustmail.com:
>
>
> > Once you discover a good data structure, the coding it up is
> easy(ish).
> >
>
> I'll take your word for it, but I am a newbie and the thing is,
> while I appreciate your actually providing the whole code
> structure, I just don't understand what it is and how it works.
> I see that you're splitting the array elements and making a hash
> of hashes and know what both of those are, but... this part just
> sails over my head at warp speed.

OK. let us take a look.

at this point %domains contains the hash of hashes
domain=>\%accounts   and each %accounts is
account=>count

>
> > my %acct_totals;
> > foreach my $domain ( sort keys %domains ) {
I assume you got this

> >    my($total, @accts);
preparing subtotal for this domain and a list of accounts
they are both nulled

> >    foreach my $acct ( sort keys %{$domains{$domain}} ) {
loop through the accounts for this domain

> >       $acct_totals{$acct} += $domains{$domain}{$acct};
we add this account's count to the overall total count

> >       $total              += $domains{$domain}{$acct};
and to this domain's subtotal count

> >       push @accts, "           $acct=
> $domains{$domain}{$acct}\n";
we add to this domain's list a string showing the account
and it's count

> >    }
end of this domains account loop
now we can report on this domain

> >    print "domain $domain = $total entries\n";
print out the domain's subtotaltotal

> >    print for @accts;
this prints out the list we made for this domain.
the minimal 'for' uses the default iterator $_,
which is also the default argument for print.
no need for newlines, because we added a newine to each
list element with the 'push' above.

> >    print "\n";
print extra newline to separate the domains from each other
> > }
>
> What exactly is happening here?
clearer?

gnari






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

Date: Thu, 12 Feb 2004 13:51:34 +1100
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: compile Perl as a STATIC library
Message-Id: <402aeb33$0$1740$5a62ac22@freenews.iinet.net.au>

Torsten Mohr wrote:
> Hi,
> 
> i downloaded, compiled and installed Perl successfully on Win32.
> I can now write programs that use the Perl interpreter to execute
> some scripts.  That's just fine.
> 
> But if i want to distribute this code to some other PCs, i need
> to install Perl there completely, not just the perl58.dll, but
> also the modules.
>

If they're perl scripts, then use PAR to build them into executables and
distribute those executables with the perl58.dll. (No need to distribute
the modules as well.)

> Is there some way to compile Perl as a STATIC library that already
> includes all modules that come with a normal Perl installation?
> 

I spent a few minutes googling for info on how to build a static perl on
native win32 - also did a quick search of the ActiveState mailing list
archives - and found nothing. Would you let me know if you come up with
some info on how to achieve it ?

It might be readily achievable with Cygwin - though I personally have no
interest in following that route.

Cheers,
Rob

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



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

Date: Wed, 11 Feb 2004 22:20:46 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Encrypt and Decrypt for text ...
Message-Id: <giCWb.7758$lK.533843@news20.bellglobal.com>


"Ben Morrow" <usenet@morrow.me.uk> wrote in message
news:c0em79$ish$1@wisteria.csv.warwick.ac.uk...
>
> Klaas <spamhole@klaas.ca> wrote:
> > I agree.  I was essentially objecting to the poster's characterizing DES
> > as the best known algorithm (I should have realized he meant
best-known).
>
> Yay! Punctuation Pedants of the World Unite!
>

Our long-awaited call to arms! Quick, everyone to the Tower of Babel! : )

Matt




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

Date: Thu, 12 Feb 2004 05:13:49 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Encrypt and Decrypt for text ...
Message-Id: <Xns948D257ECE43dkwwashere@216.168.3.30>

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote:

> Encryption doesn't have to be perfect: it just has to be good
> enough to not be worth the bother of breaking.

($encrypted = $plaintext) =~ tr/A-Za-z/N-ZA-Mn-za-m/;

is often good enough...  :-)

In meetings, I often use runes from The Hobbit to make notes such as "This 
person is just pushing their pet project" or "This is boring".



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

Date: Thu, 12 Feb 2004 06:22:28 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: formating pipe delimited file
Message-Id: <402B1B47.F6589E1E@acm.org>

J wrote:
> 
> I have a file with 40000 lines.  Each line is a row of data, and the fields
> are seperated by pipes ( | ).  I would like to align all pipes so that the
> fields will line up.
> 
> example:
> 
> field1  | 100 | 1 | | |
> field2islong| | example | | 3 |
> 
> would become
> 
> field1      | 100 | 1       | |   |
> field2islong|     | example | | 3 |
> 
> anyone have any ideas.

Something like this should work:

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

( $^I, @ARGV ) = ( '.bak', 'yourfile.txt' );

my @lens = map length, split /\|/, <>, -1;
while ( <> ) {
    chomp;
    my $i = -1;
    $lens[ ++$i ] < $_ and $lens[ $i ] = $_ for map length, split /\|/, $_, -1;
    }
@ARGV = $ARGV;
while ( <> ) {
    chomp;
    my $i;
    print join( '|', map sprintf( '%-*s', $lens[ $i++ ], $_ ), split /\|/, $_, -1 ), "\n";
    }

__END__



John
-- 
use Perl;
program
fulfillment


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

Date: 12 Feb 2004 09:57:30 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: formating pipe delimited file
Message-Id: <c0fima$hlf$2@mamenchi.zrz.TU-Berlin.DE>

J  <webstuff@fluidic.com> wrote in comp.lang.perl.misc:
> I have a file with 40000 lines.  Each line is a row of data, and the fields 
> are seperated by pipes ( | ).  I would like to align all pipes so that the 
> fields will line up.
> 
> example:
> 
> field1  | 100 | 1 | | |
> field2islong| | example | | 3 |
> 
> would become
> 
> field1      | 100 | 1       | |   |
> field2islong|     | example | | 3 |

Ah... an alignment problem.  That's an occasion to plug Text::Table :)

    use Text::Table;

    # Define a table with 5 columns, untitled, with "|" as column separators
    my $tb = Text::Table->new( ('', \ '|') x 5);

    # Fill in the data lines
    $tb->add( split /\|/) while <DATA>;

    # print the re-formatted lines
    print $tb;

    __DATA__
    field1  | 100 | 1 | | |
    field2islong| | example | | 3 |


Anno


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

Date: Wed, 11 Feb 2004 23:40:29 -0600
From: Changhao Jiang <jiangchanghao@hotmail.com>
Subject: non-aggressive regular expression matching?
Message-Id: <c0f3kd$33t$1@news.ks.uiuc.edu>

Any one knows how to match a regular expression in perl non-aggressively?

For example, a patttern "s/\(.*\)/haha/g" matching string "(abc) (cde)" 
will output "haha". But how can I make it output "haha haha"?

thanks,
Changhao


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

Date: Thu, 12 Feb 2004 00:48:55 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Changhao Jiang <jiangchanghao@hotmail.com>
Subject: Re: non-aggressive regular expression matching?
Message-Id: <Pine.SOL.3.96.1040212004811.7194A-100000@vcmr-86.server.rpi.edu>

[posted & mailed]

On Wed, 11 Feb 2004, Changhao Jiang wrote:

>Any one knows how to match a regular expression in perl non-aggressively?
>
>For example, a patttern "s/\(.*\)/haha/g" matching string "(abc) (cde)" 
>will output "haha". But how can I make it output "haha haha"?

You want "non-greedy" quantifiers.  To put it simply, place a ? after your
quantifier, and it will opt to match as little as possible to result in a
successful match.

  s/\(.*?\)/haha/g;


-- 
Jeff Pinyan            RPI Acacia Brother #734            2003 Rush Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: 11 Feb 2004 22:29:04 -0800
From: ajs@ajs.com (Aaron Sherman)
Subject: Re: Optimization request
Message-Id: <eaa2c627.0402112229.33b24618@posting.google.com>

"David K. Wall" <dwall@fastmail.fm> wrote in message news:<Xns9486C8112D71Adkwwashere@216.168.3.30>...

> Might I suggest that you read my post too quickly?

No, I did not. He didn't ask which you would prefer, or how you would
explain a speed difference, he asked which was faster for you, and you
didn't answer that.

I only jump on this because I've asked similar questions over the
years, and I always get people who answer based on gut reaction. With
Perl especially, where the language is defined by a single
implementation with a maze of special-case optimizations, you simply
cannot look at a piece of code and say, "well that one has more steps,
so it's less efficient." It might well work that way in that case, but
unless you run the numbers, you have no real idea.


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

Date: Thu, 12 Feb 2004 06:56:28 GMT
From: thumb_42@yahoo.com
Subject: Re: Optimization request
Message-Id: <wsFWb.157395$U%5.714447@attbi_s03>

Guru03 <Guru03@despammed.com> wrote:
> For you, it's faster this:
> 
> s/>/&gt;/g;
> 
> or this:
> 
> s/>/&gt;/g if index ($_, '>');
> 
> and why?

It's going to depend on the application, how large the string is, how 
frequently >'s appear in the text, which version of perl you're using
and so forth. If you do it once or twice it'd almost certainly be slower
just because of the time it'd take perl to compile the code.

I believe index() uses the boyer moore(sp?) algorithm to locate strings,
which is faster with longer key strings, but '>' is only one character so
the algorithm isn't going to help. (Does perl detect this and switch to
another algorithm? anyone know?) Not sure what perl's regex handling does,
as far as short-circuit testing, but I suspect it changes slightly with each
perl version. So.. in some machines it may be faster other places it'd be
slower.

If you only do it a few thousand times, it's definately not going to be
worth it. Might also look into the 'o' modifier.

It's a fun thing to think about, but another fun thing to think about is
that, by the time you've read this message, perl could have probably converted
the whole string to an array of characters, iterated over each one replacing >
with '&gt;' several hundred million times on a low end 486.

Jamie


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

Date: 12 Feb 2004 01:51:51 -0800
From: kewlkarun@yahoo.com (KK)
Subject: perl 'sendmail' equivalent in windows
Message-Id: <c8fd5039.0402120151.4fbbbb1d@posting.google.com>

Wondering if anyone can help me in finding the perl's 'sendmail'
equivalent command for windows. I want to send a mail from a window
machine. regards,


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

Date: Thu, 12 Feb 2004 11:01:23 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: perl 'sendmail' equivalent in windows
Message-Id: <c0fj4o$14lgja$1@ID-184292.news.uni-berlin.de>

KK wrote:
> Wondering if anyone can help me in finding the perl's 'sendmail'
> equivalent command for windows.

There is no "perl's sendmail command". sendmail is a mail transfer 
agent that is typically available on *nix platforms. Another thing is 
that you often open a pipe to sendmail from Perl programs when you 
want to send messages.

> I want to send a mail from a window machine.

One option is to have sendmail.exe installed, and do as you would have 
done on *nix. Another option is to send the message directly from Perl 
by making use of one of the many Perl modules for the purpose. 
Personally I have good experiences from using Mail::Sender.

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



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

Date: Thu, 12 Feb 2004 11:11:05 +0100
From: Bernard El-Hagin <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: perl 'sendmail' equivalent in windows
Message-Id: <slrnc2mk3n.122e.bernard.el-haginDODGE_THIS@gdndev25.lido-tech>

On 2004-02-12, KK <kewlkarun@yahoo.com> wrote:
> Wondering if anyone can help me in finding the perl's 'sendmail'
> equivalent command for windows. I want to send a mail from a window
> machine. regards,


Perl doesn't have a sendmail command.


-- 
Cheers,
Bernard


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

Date: 11 Feb 2004 23:12:29 -0800
From: csdude@hotmail.com (Mike)
Subject: Re: Perl usage these days?
Message-Id: <46cdc619.0402112312.71cafdb3@posting.google.com>

> Just a curious question:
> 
> What is perl being used for these days?

I've been a web designer for about 8 years, and every single site I've
done has used Perl in one way or another. Most of them use Perl pretty
extensively if you count all of the SSI and backend programming. The
main reason is so that I can be sure that the code will be stable
regardless of the end-user capabilities, unlike Java.

Mike


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

Date: Thu, 12 Feb 2004 08:05:44 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: RFC: utils.pm
Message-Id: <pan.2004.02.12.05.32.22.510976@aursand.no>

On Wed, 11 Feb 2004 21:59:46 +0000, Uri Guttman wrote:
> i meant the now* funcs. they call time internally and can be skewed
> between neighboring calls. see my first followup.

And?  Is that a problem?

  my $now1 = now();
  sleep(3600);
  my $now2 = now();

Do you mean that they should be the same?  Just a reminder for you:  These
functions ('now_*') does nothing else than grabbing the current time,
formatting it and returning it.  How can values be skewed?  I only grab
the time value once for each of them...!?

I must misunderstand something.


-- 
Tore Aursand <tore@aursand.no>
"The purpose of all war is ultimately peace." -- Saint Augustine


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

Date: Thu, 12 Feb 2004 07:24:44 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: RFC: utils.pm
Message-Id: <x7ptck4v5w.fsf@mail.sysarch.com>

>>>>> "TA" == Tore Aursand <tore@aursand.no> writes:

  TA> On Wed, 11 Feb 2004 21:59:46 +0000, Uri Guttman wrote:
  >> i meant the now* funcs. they call time internally and can be skewed
  >> between neighboring calls. see my first followup.

  TA> And?  Is that a problem?

  TA>   my $now1 = now();
  TA>   sleep(3600);
  TA>   my $now2 = now();

  TA> Do you mean that they should be the same?  Just a reminder for you:  These
  TA> functions ('now_*') does nothing else than grabbing the current time,
  TA> formatting it and returning it.  How can values be skewed?  I only grab
  TA> the time value once for each of them...!?

	my $now1 = now_day() ;

midnight happens NOW!!!

	my $now2 = now_hour() ;

	my $timestamp = "$now1:$now2" ;

that is not the value you expect. a bug. not a likely bug but
effectively similar to a race condition.

the solution is to grab time once and pass it to the now() funcs which
is what strftime( "format", localtime() ) does.

  TA> I must misunderstand something.

yes, you did. you didn't understand the possibility of time changing
between now*() calls.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 12 Feb 2004 07:51:06 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: RFC: utils.pm
Message-Id: <KfGWb.157961$U%5.715761@attbi_s03>

Ben Morrow wrote:

> Tore Aursand <tore@aursand.no> wrote:
>>    trim( $value ) - Combines ltrim() and rtrim(). 
> 
> $value =~ s/^\s*(.*?)\s*$/$1/;
> or some such.

I've always heard that two anchored single-wildcard searchs are
faster than a single regex with three wildcards.

   $value =~ s/^\s+//; $value =~ s/\s+$//;

	-Joe


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

Date: Thu, 12 Feb 2004 11:13:01 +0100
From: "kz" <notpublic@restricted.com>
Subject: Same problem building several modules on XP using Visual Studio .NET
Message-Id: <0pIWb.1$ao3.1067@news.uswest.net>

Hallo Gurus,

I understand that this problem in NOT strictly Perl related, and I would
probably be better off in a M$ newsgroup. I assumed though that the solution
of this problem can be useful for several Windows Perl coders, therefore I
posted here. Apologies if my assumption was inappropriate.

I wanted to upgrade Tk (and install several new modules) on my system and I
have been following Chris Whiting's recommendations as posted in
http://groups.google.ca/groups?selm=3fe1226b_8%40news.athenanews.com on how
to install VS .NET.

After installation completed and the machine rebooted I tried to build Tk
using the usual sequence
perl makefile.pl
nmake
nmake test
nmake install

However nmake aborts with a screen saying "This application has failed to
start because mspdb71.dll was not found. reinstalling the application may
fix this problem." Typical Microsoft problem description, isn't it?
This dll is invoked when cl.exe - the command line C compiler - is called.

The relevant environment settings are:

INCLUDE="D:\Program Files\Microsoft SDK\include\";"C:\Program
Files\Microsoft Visual Studio .NET 2003\Vc7\include\";"D:\Program
Files\Microsoft.NET\SDK\v1.1\include\";

LIB="D:\Program Files\Microsoft SDK\Lib\";"C:\Program Files\Microsoft Visual
Studio .NET 2003\Vc7\lib\";"D:\Program Files\Microsoft.NET\SDK\v1.1\Lib\";

Path=D:\Perl\bin\;C:\WINDOWS\system32;C:\WINDOWS;"C:\Program Files\Microsoft
Visual Studio .NET 2003\Vc7\bin\";"C:\Program Files\Microsoft Visual Studio
 .NET 2003\Common7\IDE\";"D:\Program Files\Microsoft SDK\Bin\";"D:\Program
Files\Microsoft.NET\SDK\v1.1\Bin\";"D:\Program Files\Microsoft
SDK\Bin\Win64\";C:\Program Files\Far


The file mspdb71.dll claimed to be missing does reside in the folder
C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\

Typing mspdb71.dll from the command prompt (from another folder) invokes the
"open with" dialog and I can open the file using notepad.
The path settings are also correct because I placed a small batch file
echoing a message in this folder and invoked it from another folder.

I think there are some other dependencies which did not get installed.

Could you please give me a hint what I should check next? Your help will be
very much appreciated.

Thanks in advance and best regards,

Zoltan Kandi, M. Sc.




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

Date: Thu, 12 Feb 2004 12:11:45 +0530
From: Ajay <ajay_kumarsingh@yahoo.com>
Subject: Re: Search and replace string
Message-Id: <402B2029.9D95836A@yahoo.com>



Ian Cass wrote:
> 
> ajay wrote:
> 
> > i expected a clearcut solution
> 
> I think the guys here will help you to help yourself but won't do your work
> for you.
yeh that's right
But i'm stuck that's why i posted this problem

> --
> Ian Cass


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

Date: Thu, 12 Feb 2004 10:17:15 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Search and replace string
Message-Id: <c0fgi3$15s995$1@ID-184292.news.uni-berlin.de>

Ajay wrote:
> Ian Cass wrote:
>> ajay wrote:
>>> i expected a clearcut solution
>> 
>> I think the guys here will help you to help yourself but won't do
>> your work for you.
> 
> yeh that's right
> But i'm stuck that's why i posted this problem

Then post your best attempt you made by help of the documentation and
somebody may be willing to help you correct it.

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



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

Date: Thu, 12 Feb 2004 09:05:38 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Search and replace string
Message-Id: <c0ffja$t9d$1@news.simnet.is>

"Ajay" <ajay_kumarsingh@yahoo.com> wrote in message
news:402A15F5.1F20D07B@yahoo.com...
> Hi All,
[snipped replace problem]

[snipped program]

your program (after the replace) would only print the 2 lines in
question. I thought you wanted the whole file, but with these lines changed.

the usual way to do that is make a program that reads a file,
makes the changes, and prints all the lines. then you call it like:

    myprog orig_file > new_file
or
    someprogram_making_output | myprog > fixed_output

if you do that you can let perl deal with opening files and looping and
stuff
by using commandline switches

attention: no line break in command line:
    perl -pe '$found=1 if !$found &&
s/cgipp=(\S+)/cgipp=0x0600b0/;s/STINCSAP=(\S+)/STINCSAP=blablabla/'
orig_file > new_file

if you want you can do 'inplace' replace
    perl -pi.bak -e '$found=1 if !$found &&
s/cgipp=(\S+)/cgipp=0x0600b0/;s/STINCSAP=(\S+)/STINCSAP=blablabla/'
orig_file

this will change the original file, but make a backup copy ori_file.bak

(please test the above before using it on anything critical, as I just typed
it
without any testing, and I may have misunderstood your requirements)

gnari






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

Date: Wed, 11 Feb 2004 23:16:01 -0700
From: Bill <wherrera@lynxview.com>
Subject: Re: Term::Prompt broken? Or am I misreading documentation?
Message-Id: <j4Sdnbvce-eWh7bdRVn-iQ@adelphia.com>

Daniel M. Drucker wrote:

> Term::Prompt appears to be either very badly broken ... or I'm
> completely misreading the documentation.
> 
> Term::Prompt's menuing system really doesn't seem to behave anything
> like described in the documentation.
> 
> In this script, only the first prompt displays a menu at all, and
> misnumbered, at that.
> 
> Can ANYONE tell me if I'm doing something wrong, or if this is a bug
> in Term::Prompt?
> 
> Daniel Drucker
> dmd@3e.org
> 
> #!/usr/bin/perl
> 
> use Term::Prompt;
> 
> my @fruits = qw(apple orange pear tomato grapefruit apricot peach);
> 
> my $fruitnum = &prompt("m", {
>     prompt => "Choose:",
>       title => "Fruits",
>       items => [@fruits],
>       order => 'down',
>       accept_empty_selection => 0,
>       accept_multiple_selections => 0,
> });
> 

I'm pretty sure that the above is not a correct call of the 'prompt'
function. Though why it behaves the way it does is unclear. What happens 
if you add 'use strict'?



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

Date: Thu, 12 Feb 2004 04:38:29 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Using Tie::IxHash order a hash reference
Message-Id: <c0esmc$16b5iq$1@ID-184292.news.uni-berlin.de>

Jeff 'japhy' Pinyan wrote:
> 
>   use Tie::IxHash;
> 
>   local ($,) = ("\n", " ");
>   my ($r1,$r2);
> 
>   tie %$r1, 'Tie::IxHash';
> 
>   @$r1{a..z} = @$r2{a..z} = ();
> 
>   print for keys %$r1, "\n";  # abcdefghijklmnopqrstuvwxyz
>   print for keys %$r2, "\n";  # wraxdjyukhgftienvmslcpbqzo
> 
> Perl 5.8.0 seems to handle the situation just fine.

Hmm.. Please consider the following example:

     use Tie::IxHash;
     my ($r1,$r2,$r3);
     tie %$r1, 'Tie::IxHash';
     tie %$r2, 'Tie::IxHash';
     tie %$r3, 'Tie::IxHash';

     print $r2, "\n";                # HASH(0x158123c)

     %$r1 = ( one => 1, two => 2, three => 3 );
     $r2 =  { one => 1, two => 2, three => 3 };

     print $r2, "\n";                # HASH(0x158132c)
                                     # -----------^^
     $r3->{one}   = 1;
     $r3->{two}   = 2;
     $r3->{three} = 3;

     print $r1->{$_} for keys %$r1;  # 123
     print "\n";
     print $r2->{$_} for keys %$r2;  # 312
     print "\n";
     print $r3->{$_} for keys %$r3;  # 123
     print "\n";

I'd appreciate some help to understand what I'm doing. :)
Is the difference in result because the construct

     $hashref = { };

*always* creates a *new* anonymous hash, dropping previously created 
referent?

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



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

Date: Wed, 11 Feb 2004 23:18:45 -0500
From: Kevin Michael Vail <kevin@vaildc.net>
Subject: Re: Using Tie::IxHash order a hash reference
Message-Id: <kevin-734370.23184511022004@news101.his.com>

In article <c0esmc$16b5iq$1@ID-184292.news.uni-berlin.de>,
 Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:

>      use Tie::IxHash;
>      my ($r1,$r2,$r3);
>      tie %$r1, 'Tie::IxHash';
>      tie %$r2, 'Tie::IxHash';
>      tie %$r3, 'Tie::IxHash';
> 
>      print $r2, "\n";                # HASH(0x158123c)
> 
>      %$r1 = ( one => 1, two => 2, three => 3 );
>      $r2 =  { one => 1, two => 2, three => 3 };
> 
>      print $r2, "\n";                # HASH(0x158132c)
>                                      # -----------^^
>      $r3->{one}   = 1;
>      $r3->{two}   = 2;
>      $r3->{three} = 3;
> 
> I'd appreciate some help to understand what I'm doing. :)
> Is the difference in result because the construct
> 
>      $hashref = { };
> 
> *always* creates a *new* anonymous hash, dropping previously created 
> referent?

Yup, you got it.  Perl evaluates the right side of the assignment and 
then stuffs it into the left side, throwing away whatever was there 
before; in this case, the reference to the tied hash.
-- 
Found Poetry (_Science News_, 14-Jun-2003): oldest _homo sapiens_ find
+-----------------------------------------+ ocean eddies' far-flung effects;
|  Kevin Michael Vail <kevin@vaildc.net>  | superior threads spun
+-----------------------------------------+ the pox from prairie dogs.


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

Date: Thu, 12 Feb 2004 00:56:01 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: Using Tie::IxHash order a hash reference
Message-Id: <Pine.SOL.3.96.1040212004902.7194B-100000@vcmr-86.server.rpi.edu>

On Thu, 12 Feb 2004, Gunnar Hjalmarsson wrote:

>     use Tie::IxHash;
>     tie %$r2, 'Tie::IxHash';
>
>     print $r2, "\n";                # HASH(0x158123c)
>     $r2 =  { one => 1, two => 2, three => 3 };
>     print $r2, "\n";                # HASH(0x158132c)

>I'd appreciate some help to understand what I'm doing. :)
>Is the difference in result because the construct
>
>     $hashref = { };
>
>*always* creates a *new* anonymous hash, dropping previously created 
>referent?

Right.  The hash that is tied is no longer accessible via %$r2, because
$r2 refers to a different hash reference.

-- 
Jeff Pinyan            RPI Acacia Brother #734            2003 Rush Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: Thu, 12 Feb 2004 10:47:15 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Using Tie::IxHash order a hash reference
Message-Id: <c0fiad$15idgf$1@ID-184292.news.uni-berlin.de>

Gunnar Hjalmarsson wrote:
> 
>     use Tie::IxHash;
>     tie %$r2, 'Tie::IxHash';
> 
>     print $r2, "\n";                # HASH(0x158123c)
> 
>     $r2 =  { one => 1, two => 2, three => 3 };
> 
>     print $r2, "\n";                # HASH(0x158132c)
>                                     # -----------^^
> 
> Is the difference in result because the construct
> 
>     $hashref = { };
> 
> *always* creates a *new* anonymous hash, dropping previously
> created referent?

Thanks, Kevin and Jeff, for helping me realize my mistake. Sometimes
it takes some time to do so...

Btw, I think that OP may have made the same mistake that I did:

Darius wrote:
> How can I order the entries in a hash if I use a reference to a
> hash instead of a hash. For e.g.
> 
> $ref={
> key=>"value",
> };
> 
> instead of
> 
> %ref=(
> key=>"value",
> );

But now he should have got enough guidance from this thread to solve
whatever problem he had. :)

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



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

Date: 12 Feb 2004 00:46:55 -0800
From: thomaspoly@mail.com (Tompyna)
Subject: When i try to implement a server program giving UDP as protocol , it works fine ,  but if the same code is executed with TCP as protocol option, it gives an error.
Message-Id: <9af8a23a.0402120046.1c7dd15d@posting.google.com>

Hi All,

        I am a newbie to Socket Programming . I had written a socket
program in perl , implementing  client and server.

Now coming to the problem i am stuck:

1.When i implement the program with "UDP" as protocol option, the code
works
  fine,but When i try to implement the same program , giving TCP as
the
  protocol  option,  it gives me an error:
 "Can't call method "recv" on an undefined value at servermodulenew.pl
line 18"
  
  I believe the method "recv" should be called irrespective of the 
  protocol option i give.        

  Hope someone could possibly give me an answer to this  problem.

(Below is the code for server implementation)
NOTE: The program is executing on solaris and run as a background
process.

The server Program i implemented is:

/************************************************/
# Server Program

use IO::Socket;

my $port = 1024;

#use ngd_simulator::thomasp::perl::Socket;

my $receive_status;

print ">> Server Program <<\n";

# Create a new socket
$MySocket=new IO::Socket::INET->new(LocalPort=>($port),Proto=>(getprotobyname('udp')));

while(1)
  {    
    #Receiving a message from the client
    $receive_status = $MySocket->recv($text,128);
	
    if($text ne '')
      {
	print "\nReceived message ===>", $text,"\n";
  
      }
    # If client message is empty exit
    else
      {
	print "Cilent has exited!";
	exit 1;
  
      }
  }
#Close the Socket after sending the message
close($MySocket);

/******************************************************/



  Thanx.... in advance,
  Thomas Poly.


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

Date: Thu, 12 Feb 2004 09:20:30 GMT
From: thumb_42@yahoo.com
Subject: Re: When i try to implement a server program giving UDP as protocol , it works fine ,  but if the same code is executed with TCP as protocol option, it gives an error.
Message-Id: <yzHWb.293967$na.450248@attbi_s04>

In comp.lang.perl.misc Tompyna <thomaspoly@mail.com> wrote:
 
> 1.When i implement the program with "UDP" as protocol option, the code
> works
>  fine,but When i try to implement the same program , giving TCP as
> the
>  protocol  option,  it gives me an error:
> "Can't call method "recv" on an undefined value at servermodulenew.pl
> line 18"

Thats because TCP doesn't have a recv. :-)

UDP is connection-less, you're responsible for any network errors and
dropped packets, it has a lot in common with the US postal service, in that
it will loose your mail and not care.

TCP is more like a phone connection, so the methods are different.

(TCP and UNIX sockets are a lot like working with file handles)

Jamie


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

Date: 12 Feb 2004 09:36:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: When i try to implement a server program giving UDP as protocol , it works fine ,  but if the same code is executed with TCP as protocol option, it gives an error.
Message-Id: <c0fhee$hlf$1@mamenchi.zrz.TU-Berlin.DE>

Tompyna <thomaspoly@mail.com> wrote in comp.lang.perl.misc:

[...]

> 1.When i implement the program with "UDP" as protocol option, the code
> works
>   fine,but When i try to implement the same program , giving TCP as
> the
>   protocol  option,  it gives me an error:
>  "Can't call method "recv" on an undefined value at servermodulenew.pl
> line 18"

[...]

> The server Program i implemented is:
> 
> /************************************************/
> # Server Program

No strict, no warnings.  Switch them on.

> use IO::Socket;
> 
> my $port = 1024;
> 
> #use ngd_simulator::thomasp::perl::Socket;
> 
> my $receive_status;
> 
> print ">> Server Program <<\n";
> 
> # Create a new socket
> $MySocket=new

You have declared other variables lexicals.  Why is $MySocket a package
variable?  

> IO::Socket::INET->new(LocalPort=>($port),Proto=>(getprotobyname('udp')));

This is the statement that returns an undefined value for $MySocket.  Why
don't you ask why?

    my $MySocket = new IO::Socket::INET->new(
        LocalPort=>($port),Proto=>(getprotobyname('udp'))) or
        die "Socket error: $!";

I notice that you call the new() method twice in that statement, once as
as class method and once as an object method.  I don't think you want to
do that.

[rest snipped]

Anno


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

Date: Thu, 12 Feb 2004 09:08:53 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: When i try to implement a server program giving UDP as protocol , it works fine ,  but if the same code is executed with TCP as protocol option, it gives an error.
Message-Id: <c0ffpc$tak$1@news.simnet.is>

"Tompyna" <thomaspoly@mail.com> wrote in message
news:9af8a23a.0402120046.1c7dd15d@posting.google.com...

> 1.When i implement the program with "UDP" as protocol option, the code
> works
>   fine,but When i try to implement the same program , giving TCP as
> the
>   protocol  option,  it gives me an error:
>  "Can't call method "recv" on an undefined value at servermodulenew.pl
> line 18"
>
>   I believe the method "recv" should be called irrespective of the
>   protocol option i give.

UDP is connectionless, TCP is not.

with TCP you have to
  make socket
  listen
  accept connections when they arrive
  and then read data

gnari






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

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


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