[16649] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4061 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 18 18:10:44 2000

Date: Fri, 18 Aug 2000 15:10:26 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <966636625-v9-i4061@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 18 Aug 2000     Volume: 9 Number: 4061

Today's topics:
        newbie: s/// on windows subdirs? <nospam@nowhere.net>
    Re: newbie: s/// on windows subdirs? <amonotod@netscape.net>
        obfusicate routine to count max string len in hash <rfoskett@my-deja.com>
    Re: obfusicate routine to count max string len in hash <mauldin@netstorm.net>
    Re: obfusicate routine to count max string len in hash <mauldin@netstorm.net>
    Re: obfusicate routine to count max string len in hash <stephenk@cc.gatech.edu>
    Re: obfusicate routine to count max string len in hash <lr@hpl.hp.com>
        Perl and visual Basic <marc.pauwels@skynet.be>
    Re: Perl guestbook hacking (with HTML enabled) <schmelter_tim@hotmail.com>
        perl's -T switch. <katz@underlevel.net>
    Re: perl's -T switch. <care227@attglobal.net>
    Re: Problem with hash initialization using list <lr@hpl.hp.com>
    Re: Problem with hash initialization using list <lr@hpl.hp.com>
    Re: Problem with hash initialization using list nobull@mail.com
    Re: read files from dir then write as csv??? <jeff@vpservices.com>
        Recursion Help <grichard@uci.edu>
    Re: Regex Alternation Question (Marcel Grunauer)
    Re: Regex Alternation Question (Anno Siegel)
        Simple regex problem fgont@my-deja.com
    Re: Simple regex problem <care227@attglobal.net>
    Re: Simple regex problem <katz@underlevel.net>
        Socket question on Solaris 2.7 aloisious@my-deja.com
    Re: Socket question on Solaris 2.7 <uri@sysarch.com>
    Re: substring-p (Marcel Grunauer)
    Re: substring-p <sariq@texas.net>
        Use of uninitialized value, but it's not uninitialized. <grichard@uci.edu>
    Re: Use of uninitialized value, but it's not uninitiali (Decklin Foster)
    Re: We Need Your Feedback <russ_jones@rac.ray.com>
    Re: We Need Your Feedback <amonotod@netscape.net>
    Re: Win2K; Perl from command line <Steve_Alpert@idx.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 18 Aug 2000 22:05:08 +0200
From: "Christoph" <nospam@nowhere.net>
Subject: newbie: s/// on windows subdirs?
Message-Id: <8nk4qa$9b7$1@news.rrz.Uni-Koeln.DE>

Could someone point me to a perl script that will perform a string
substitution on all files that have one of several given file extensions
(for example *.htm and *.html and *.txt) in a directory and all of its
subdirectories on a Windows (!) system?

All the examples for this problem I could find were for Unix systems.
Thanks.

Christoph

(catheideckercat@lycosmail.com -- remove the two pets from address)




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

Date: Fri, 18 Aug 2000 20:43:11 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: newbie: s/// on windows subdirs?
Message-Id: <8nk74q$ogn$1@nnrp1.deja.com>

In article <8nk4qa$9b7$1@news.rrz.Uni-Koeln.DE>,
  "Christoph" <nospam@nowhere.net> wrote:
> Could someone point me to a perl script that will perform a string
> substitution on all files that have one of several given file
extensions
> (for example *.htm and *.html and *.txt) in a directory and all of its
> subdirectories on a Windows (!) system?
>
> All the examples for this problem I could find were for Unix systems.
> Thanks.
>
So use 'em.  Just change the path from /usr/account/web/pub to
e:/webroot/account/pub or whatever.  Those kind of basic Perl scripts
will run just fine on most Win32 systems, so long as you keep the
pathing straight.

File::Copy, File::Find, and File::Recurse all work on most platforms.
Just go for it.

> Christoph
>
> (catheideckercat@lycosmail.com -- remove the two pets from address)
>
>

HTH,
amonotod


--
    `\|||/                     amonotod@
      (@@)                     netscape.net
  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 18 Aug 2000 19:39:26 GMT
From: rog <rfoskett@my-deja.com>
Subject: obfusicate routine to count max string len in hash
Message-Id: <8nk3db$ju8$1@nnrp1.deja.com>

Hi, bit silly really but I am trying to come up with the shortest bit
of code to return the length of the longest string in a hash.

here are my ideas so far:

---------------------------------------------------
use strict;
my %hash = (
             "Z12"         => "L3",
             "Z12345"      => "L6",
             "Z1"          => "L2",
             "Z1234567890" => "L11",
             "Z123"        => "L4",
             "Z"           => "L1",
             ""            => "L0",
           );

my $mlen;

# idea 1 (WRONG!)
#$mlen = (map{length}keys%hash)-1;

# idea 2 (wrong so far...)
#my $c=0; $c = grep{length > $c} keys%hash;
#$mlen = $c;

# idea 3 (plain stupid)
#my %c = reverse map{length}keys%$hash;
#$mlen = $#c; # then can sprintf("%-$#{c}s"
#foreach (keys %c) {
#    print "$_  = $c{$_}\n";
#}

# solution 1 (CORRECT, but want rid of spare var)
#my @c;map{$c[length]=1}keys%hash;
#$mlen = $#c; # then can sprintf("%-$#{c}s"

# solution 2 (OK BUT WAY TOO LONG & STUPID)
#($mlen) = sort{length$b<=>length$a}keys%hash;
#$mlen = length($mlen);


# -- output -- #
my $outstr = "";
foreach my $key (keys %hash) {
    $outstr .= sprintf("%-${mlen}s = %s\n",$key,$hash{$key});
}
print $outstr."MAX LEN = $mlen\n";

---------------------------------------------------
I am interested in seeing if it can be done shorter, and as you can see
solution 1 is the best ive come up with. Any ideas anyone?
cheers

rog


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 18 Aug 2000 20:48:31 GMT
From: Jim Mauldin <mauldin@netstorm.net>
Subject: Re: obfusicate routine to count max string len in hash
Message-Id: <399DA06E.27DD50D7@netstorm.net>

rog wrote:
> 
> Hi, bit silly really but I am trying to come up with the shortest bit
> of code to return the length of the longest string in a hash.
> 
> here are my ideas so far:
> 
> ---------------------------------------------------
> use strict;
> my %hash = (
>              "Z12"         => "L3",
>              "Z12345"      => "L6",
>              "Z1"          => "L2",
>              "Z1234567890" => "L11",
>              "Z123"        => "L4",
>              "Z"           => "L1",
>              ""            => "L0",
>            );
 
[... various ideas ...]

> I am interested in seeing if it can be done shorter, and as you can see
> solution 1 is the best ive come up with. Any ideas anyone?


Is this shorter?

print length [sort keys %hash]->[-1];

-- Jim


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

Date: Fri, 18 Aug 2000 21:21:25 GMT
From: Jim Mauldin <mauldin@netstorm.net>
Subject: Re: obfusicate routine to count max string len in hash
Message-Id: <399DA828.BC85F1A0@netstorm.net>

I wrote:
> 
> print length [sort keys %hash]->[-1];

I should have been much more thoughtful before I posted that.  It will
only work for your particular hash.  A more general solution is:

print [sort {$a<=>$b} map length, keys %hash]->[-1];

-- Jim


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

Date: Fri, 18 Aug 2000 17:29:18 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: obfusicate routine to count max string len in hash
Message-Id: <399DAAAE.35638860@cc.gatech.edu>

rog wrote:

> Hi, bit silly really but I am trying to come up with the shortest bit
> of code to return the length of the longest string in a hash.
>
> I am interested in seeing if it can be done shorter, and as you can see
> solution 1 is the best ive come up with. Any ideas anyone?
> cheers
>

Shortest I can think of that doen't use extra variables is:
$mlen=(sort{$b<=>$a}map{length}keys%hash)[0];

--
Stephen Kloder               |   "I say what it occurs to me to say.
stephenk@cc.gatech.edu       |      More I cannot say."
Phone 404-874-6584           |   -- The Man in the Shack
ICQ #65153895                |            be :- think.




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

Date: Fri, 18 Aug 2000 14:19:50 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: obfusicate routine to count max string len in hash
Message-Id: <MPG.1407485462011f9798ac97@nntp.hpl.hp.com>

In article <399DA06E.27DD50D7@netstorm.net> on Fri, 18 Aug 2000 20:48:31 
GMT, Jim Mauldin <mauldin@netstorm.net> says...
> rog wrote:
> > 
> > Hi, bit silly really but I am trying to come up with the shortest bit
> > of code to return the length of the longest string in a hash.

 ...

> print length [sort keys %hash]->[-1];

Shorter and more efficient (no need to create a temporary array from the 
list):

  print length +(sort keys %hash)[-1];

But of course this is an O(N log N) solution; an O(N) solution would 
require more strokes.

  my $x = 0;
  $x > length or $x = length for keys %hash;
  print $x;

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 18 Aug 2000 21:29:36 GMT
From: <marc.pauwels@skynet.be>
Subject: Perl and visual Basic
Message-Id: <spram07g87v134@corp.supernews.com>


Hi,

I have some troubles to return a string from a visual basic program, which 
is called from a PERL script into a perl variable. 
ex. 

     $perlvar = my_vb_program("var1,var2.....") ;

How can I get the returned string into my $perlvar and syntax of my the 
visual basic code ?  

Any idea ? please let me known ? 
Thanks. Bye



--
Posted via CNET Help.com
http://www.help.com/


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

Date: Fri, 18 Aug 2000 12:32:56 -0500
From: "Tim Schmelter" <schmelter_tim@hotmail.com>
Subject: Re: Perl guestbook hacking (with HTML enabled)
Message-Id: <8njs0e027a5@enews1.newsguy.com>

"Sandra" <sandra@siliconrack.com> wrote in message
news:bRjMNlKIyaRCv5FEiOYI8cnLJWDg@4ax.com...
>
> We have a simple Perl guestbook based on Matt W.'s guestbook,
> we have HTML enabled. Server is redhat 6.1
>
> Question:
>
> 1. I read somewhere it's easy to hack servers using
> HTML-enabled perl guestbooks.  Is this true?  which procedure?
>
> 2. How to protect an HTML-enabled guestbook?
> I have a function to strip <script></script> <object>, etc, etc
> but I don't know if this is enough protection.
>
> Any ideas
> Thanks
>

To get started, try "perldoc perlsec".

--
Tim Schmelter
Magic Pictures Company
schmelter.tim@MagicPicturesCompany.com




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

Date: 18 Aug 2000 16:18:24 -0400
From: Jordan Katz <katz@underlevel.net>
Subject: perl's -T switch.
Message-Id: <m3n1iaz5kf.fsf@underlevel.underlevel.net>

Hi,

I have the following function to retrieve the source of a given URL:

  #!/usr/bin/perl -w

  use LWP::UserAgent;
  use HTTP::Request;
  use strict;

  sub get_url {
      my $url = shift;
      my $ua  = new LWP::UserAgent;
      my $req = new HTTP::Request 'GET', $url;
      $ua->timeout(30);
      my $src = $ua->request($req);

      return $src->content unless (!$src->is_success);
      return 0;
  }

Which works fine, but if I add Perl's -T switch, which adds extra
checking as I understand from perlrun, get_url fails everytime.  I was
hoping someone could clarify why.

Thanks, 
-- 
Jordan Katz <katz@underlevel.net>


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

Date: Fri, 18 Aug 2000 17:32:01 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: perl's -T switch.
Message-Id: <399DAB51.8D5DF8A0@attglobal.net>

Jordan Katz wrote:
> 
>       my $url = shift;

Tainted.

$ perldoc perlsec

http://www.perl.com/pub/doc/manual/html/pod/perlsec.html


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

Date: Fri, 18 Aug 2000 13:35:38 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Problem with hash initialization using list
Message-Id: <MPG.14073df25fd2d11b98ac94@nntp.hpl.hp.com>

In article <u9lmxun655.fsf@wcl-l.bham.ac.uk> on 18 Aug 2000 12:38:10 
+0100, nobull@mail.com <nobull@mail.com> says...
> priitr.randla@eyp.ee (Priit Randla) writes:
> 
> >  ($key,$info{$key}) = split /=/ while <> ;
> >  Obviously this does not work and i do understand why($key not evaluated yet
> >  when evaluating $info{$key}).
> 
> >  Is there some way to initialize hash _elements_ using lists as 
> >  %hash = ($key1, $val1, $key2, $val2 ) is doing for _entire_ hash?
> 
> %hash = %hash, $key, $val;

Unparenthesized, that doesn't do what you think it does.  The '-w' flag 
would warn you about this error.
 
 ...

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 18 Aug 2000 13:45:29 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Problem with hash initialization using list
Message-Id: <MPG.14074044eacd333398ac95@nntp.hpl.hp.com>

In article <8nj8q0$o5h$1@lublin.zrz.tu-berlin.de> on 18 Aug 2000 
12:05:20 -0000, Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> says...

 ...

> Another problem (that it shares with your approach) is that it neglects
> to chomp() the input lines, so all the values in %info are going to
> have a trailing newline.
> 
>    map chomp, values %info
> 
> can correct that, but that's map in void context, anathema to some.

So why not write it as

     chomp for values %info;

One token fewer, at that!

Note to the unwary:  The values() function wasn't lvaluable until 5.6.0.  
The documentation with ActivePerl 5.6.0 build 616 (the latest) still 
says explicitly that it isn't lvaluable.  It is mentioned in perldelta, 
though.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 18 Aug 2000 22:07:42 +0100
From: nobull@mail.com
Subject: Re: Problem with hash initialization using list
Message-Id: <u9hf8iqnvl.fsf@wcl-l.bham.ac.uk>

Larry Rosler <lr@hpl.hp.com> writes:

> In article <u9lmxun655.fsf@wcl-l.bham.ac.uk> on 18 Aug 2000 12:38:10 
> +0100, nobull@mail.com <nobull@mail.com> says...
> > priitr.randla@eyp.ee (Priit Randla) writes:
> > 
> > >  ($key,$info{$key}) = split /=/ while <> ;
> > >  Obviously this does not work and i do understand why($key not evaluated yet
> > >  when evaluating $info{$key}).
> > 
> > >  Is there some way to initialize hash _elements_ using lists as 
> > >  %hash = ($key1, $val1, $key2, $val2 ) is doing for _entire_ hash?
> > 
> > %hash = %hash, $key, $val;
> 
> Unparenthesized, that doesn't do what you think it does.  The '-w' flag 
> would warn you about this error.

Yup, I've been using Perl for several years and yet I still forget
that the presedence of assignment and comma are not the way one would
expect.

Having a bad day today.  That's about the third bit of rubbish I've
posted in one day.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 18 Aug 2000 11:28:52 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: read files from dir then write as csv???
Message-Id: <399D8064.5C337885@vpservices.com>

kingofkingston@my-deja.com wrote:
> 
> In article <399C27B9.9A7EF4AC@vpservices.com>,
>   Jeff Zucker <jeff@vpservices.com> wrote:
> >
> > There are many ways to do this.  Here is one way using DBI (which you
> > are probably already using for Oracle) and DBD::RAM. 

> Unfortunately I dont think
> I'll be able to implement it as the unix box the Ora DB is on is a
> client's box (internal department) and they are being very cranky about
> having to install things on it.

If they are already using DBI for Oracle, then it is a fairly simple
thing to install DBDs in your own directories.

> It look like I'll have to resort to using arrays and hashes to
> manipulate the data in the files, and find some way of outputing a CSV
> file.

You can use the part of the code I sent that captures the date,
table_name, and row_count and then just write that to CSV using any of
the modules or non-moudle methods listed in perlfaq4, or since in this
particular case in which there are no embedded anythings, just use join.

-- 
Jeff


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

Date: Fri, 18 Aug 2000 14:44:25 -0700
From: "Gabe" <grichard@uci.edu>
Subject: Recursion Help
Message-Id: <8nkb1m$57f$1@news.service.uci.edu>

It seems I can't get this recursion to work properly. The program goes down
two directories deep, but when it find there are no more directory entries
it doesn't return to the previous level. I've just discovered recursion so
I'm sure my algorithm is to blame.

opendir(DIR, $dir) or die "Could not open directory: $!";
@messagelist = map { "$dir/$_" } grep (!/^\./, readdir(DIR));
closedir(DIR);
foreach my $i (@messagelist) {
    if ($i =~ /\.html$/) {
    $parser->parse_file($i);
    my $pgid = ID('pages', 'pgid', $dbh);
    my $nid = ID('news', 'nid', $dbh);
    $addpg->execute($pgid, '1234567890', $i, $i);
    $addcon->execute($nid, $pgid, $parser->{TEXT}, '2000-08-18');
    }
    elsif ($i !~ /\./) { Recurse($i);} # If there are no dots then $i is a
directory so run the sub.
}

sub Recurse {
    my $dir = shift;
    opendir(DIR, $dir) or die "Could not open directory: $!";
    @messagelist = map { "$dir/$_" } grep (!/^\./, readdir(DIR));
    closedir(DIR);
    foreach my $i (@messagelist) {
        if ($i =~ /\.html$/) {
            $parser->parse_file($i);
            my $pgid = ID('pages', 'pgid', $dbh);
            my $nid = ID('news', 'nid', $dbh);
            $addpg->execute($pgid, '1234567890', $i, $i);
            $addcon->execute($nid, $pgid, $parser->{TEXT}, '2000-08-18');
        }
        elsif ($i !~ /\./) { Recurse($i);} # If $i is a directory do it
again! But why doesn't it come back?
    }
}


Please help.

Gabe




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

Date: Fri, 18 Aug 2000 18:09:00 GMT
From: marcel@codewerk.com (Marcel Grunauer)
Subject: Re: Regex Alternation Question
Message-Id: <slrn8pqusj.bpa.marcel@gandalf.local>

On 18 Aug 2000 14:48:57 GMT, Abigail <abigail@foad.org> wrote:
>
>I tried to automate the the process:
>
>    my $i  = -1;
>    my $re = join "|" =>
>             map {"($sub_matches[$_](?{ \$i = $_ }))"} 0 .. $#sub_matches;
[snip]
>
>But while $re contains exactly the same string as in the previous code
>fragment, $i remains -1. I've no idea why this doesn't work.


It works if you don't make $i a lexical, but declare it with

	use vars qw($i);
	...
	$i = -1;
	...

But then why does your first case (specifying the regex explicitly)
work even if $i is a lexical?


-- 
Marcel Gr\"unauer - Codewerk plc . . . . . . . . . . . <http://www.codewerk.com>
Perl Consulting, Programming, Training, Code review . . .  <marcel@codewerk.com>
mod_perl, XML solutions - email for consultancy availability
sub AUTOLOAD{($_=$AUTOLOAD)=~s;^.*::;;;y;_; ;;print} Just_Another_Perl_Hacker();


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

Date: 18 Aug 2000 21:32:06 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Regex Alternation Question
Message-Id: <8nka0m$oub$1@lublin.zrz.tu-berlin.de>

Abigail <abigail@foad.org> wrote in comp.lang.perl.misc:

[finding which part of a regex alternation matches]

>I tried to automate the the process:

[code snipped]

>    my $i  = -1;

>But while $re contains exactly the same string as in the previous code
>fragment, $i remains -1. I've no idea why this doesn't work.

I don't know either, but with a package variable $i it works as 
expected.

Anno


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

Date: Fri, 18 Aug 2000 21:11:37 GMT
From: fgont@my-deja.com
Subject: Simple regex problem
Message-Id: <8nk8pp$qck$1@nnrp1.deja.com>

Hi!

I have a variable that contains the header and the body of an e-mail.
As the header is separated from the body by two newlines "\n\n", I
tried to use a regex to separate the header and the body, buy I
couldn't make it work.
Here's what I did:

sub separate_hb(){
     $_=@_[0];
     if(/\n\n/){
          return($PREMATCH, $POSTMATCH);
     }
     else{
          return(0, 0);      # There has been an error
     }
}


The problem is that the regexp never matches... Can anyone help me?

Is the any good online tutorial on the net? I'd like to get some online
document with lots of examples and explanations about regexps... is
there anything like this?

Kind regards,

Fernando Ariel Gont
e-mail: fgont@NOSPAM.softhome.net



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 18 Aug 2000 17:35:28 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Simple regex problem
Message-Id: <399DAC20.3AF1768C@attglobal.net>

fgont@my-deja.com wrote:
> 
> Hi!
> 
> I have a variable that contains the header and the body of an e-mail.
> As the header is separated from the body by two newlines "\n\n", I
> tried to use a regex to separate the header and the body, buy I
> couldn't make it work.
> Here's what I did:
> 

why not just use split()?

($header, $footer) = split /\n\n/, $variable;


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

Date: 18 Aug 2000 17:53:07 -0400
From: Jordan Katz <katz@underlevel.net>
Subject: Re: Simple regex problem
Message-Id: <m3aeeaz16k.fsf@underlevel.underlevel.net>

fgont@my-deja.com writes:

> Hi!
> 
> I have a variable that contains the header and the body of an e-mail.
> As the header is separated from the body by two newlines "\n\n", I
> tried to use a regex to separate the header and the body, buy I
> couldn't make it work.
> Here's what I did:
> 
> sub separate_hb(){
>      $_=@_[0];

`@_[0] better written as $_[0]`

>      if(/\n\n/){
>           return($PREMATCH, $POSTMATCH);
>      }
>      else{
>           return(0, 0);      # There has been an error
>      }
> }
> 
> 
> The problem is that the regexp never matches... Can anyone help me?

Try the following:

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

  my $str = "our header\n\nour body";
  my @result = seperate_hb($str);
  print "Header: $result[0]\n";
  print "Body: $result[0]\n";

  sub seperate_hb {
      my ($header, $body) = split /\n\n/, $_[0];
      return ($header, $body);
  }

> Is the any good online tutorial on the net? I'd like to get some online
> document with lots of examples and explanations about regexps... is
> there anything like this?

Look at `perlre`.
-- 
Jordan Katz <katz@underlevel.net>


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

Date: Fri, 18 Aug 2000 19:28:34 GMT
From: aloisious@my-deja.com
Subject: Socket question on Solaris 2.7
Message-Id: <8nk2oa$j70$1@nnrp1.deja.com>

I'm attempting to use sockets.  I used some examples and perldocs to get
a talker and listener working with tcp.  I want to use udp, however, and
I am not getting the results I expect.  The listener script complains:
"Could not create socket: Protocol not supported"
I found this in perlfaq8 and tried "use Socket" as described.  I'm using
perl  v5.6.0 built for sun4-solaris on Sunos 5.7.

TIA


Listener script:
#! /usr/local/bin/perl
use IO::Socket;
my $sock = IO::Socket::INET->new (
                                 LocalAddr => 'localhost',
                                 LocalPort => '4321',
                                 Proto => 'udp',
                                 Type => 'SOCK_DGRAM',
                                 Listen => 5,
                                 Reuse => 1,
                                );
die "Could not create socket: $!\n" unless $sock;
my $new_sock = $sock->accept();
while(<$new_sock>) {
   print;
}
close($sock);
#######################

Talker script:
#! /usr/local/bin/perl
use IO::Socket;
$|=1;
my $sock = IO::Socket::INET->new (
                                 PeerAddr => 'localhost',
                                 PeerPort => '4321',
                                 LocalAddr => 'localhost',
                                 LocalPort => '4321',
                                 Proto => 'udp',
                                );
die "Could not create socket: $!\n" unless $sock;
$sock->autoflush(1);
print $sock "\n\rHello World!\n\r";
close($sock);
#######################



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 18 Aug 2000 20:18:55 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Socket question on Solaris 2.7
Message-Id: <x7bsyqwceo.fsf@home.sysarch.com>

>>>>> "a" == aloisious  <aloisious@my-deja.com> writes:

  a> my $sock = IO::Socket::INET->new (
  a>                                  LocalAddr => 'localhost',
  a>                                  LocalPort => '4321',
  a>                                  Proto => 'udp',
                                      ^^^^^^^^^^^^^^

  a>                                  Type => 'SOCK_DGRAM',
  a>                                  Listen => 5,
                                      ^^^^^^^^^^^

  a>                                  Reuse => 1,
  a>                                 );


  a> I'm attempting to use sockets.  I used some examples and perldocs
  a> to get a talker and listener working with tcp.  I want to use udp,
  a> however, and I am not getting the results I expect.  The listener
  a> script complains: "Could not create socket: Protocol not supported"
  a> I found this in perlfaq8 and tried "use Socket" as described.  I'm
  a> using perl v5.6.0 built for sun4-solaris on Sunos 5.7.

you don't create listener sockets for udp, only tcp. so drop the
listener and reuse attrtibutes. then just call the recv method to get
an incoming message.

read perlipc for more on this. the perl cookbook has examples of a udp
client and server.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Fri, 18 Aug 2000 18:11:00 GMT
From: marcel@codewerk.com (Marcel Grunauer)
Subject: Re: substring-p
Message-Id: <slrn8pqv0u.bpa.marcel@gandalf.local>

On 18 Aug 2000 13:48:47 -0400, Art Werschulz <agw@smolyak.cs.columbia.edu>
wrote:

>I would like to determine whether a particular string (say, $word)
>appears as a substring of another string (say, $keywords).  The
>obvious thing to do would be
>
>  print $word, "\n" if ($keywords =~ $word);
>
>Unfortunately, this doesn't work if (e.g) $word contains a
>parenthesis.  The main point here is that I would like $word to be
>treated as a garden variety string, not a regular expression.


Using a regex for a fixed search string isn't just overkill, it sometimes
also doesn't work, as you've discovered. Use index() instead.


perldoc -f index

       index STR,SUBSTR,POSITION

       index STR,SUBSTR
               The index function searches for one string within
               another, but without the wildcard-like behavior of
               a full regular-expression pattern match.  It
               returns the position of the first occurrence of
               SUBSTR in STR at or after POSITION.  If POSITION
               is omitted, starts searching from the beginning of
               the string.  The return value is based at `0' (or
               whatever you've set the `$[' variable to--but
               don't do that).  If the substring is not found,
               returns one less than the base, ordinarily `-1'.


-- 
Marcel Gr\"unauer - Codewerk plc . . . . . . . . . . . <http://www.codewerk.com>
Perl Consulting, Programming, Training, Code review . . .  <marcel@codewerk.com>
mod_perl, XML solutions - email for consultancy availability
sub AUTOLOAD{($_=$AUTOLOAD)=~s;^.*::;;;y;_; ;;print} Just_Another_Perl_Hacker();


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

Date: Fri, 18 Aug 2000 13:15:57 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: substring-p
Message-Id: <399D7D5D.43D059CB@texas.net>

Art Werschulz wrote:
> 
> Hi.

Hello!

> I would like to determine whether a particular string (say, $word)
> appears as a substring of another string (say, $keywords).

Perl's base functions are documented in the perlfunc page of the
manual.  Perhaps you'll find a function there that will tell you whether
a SUBSTRing occurs in a particular STRing.  Perhaps it'll even return
the index()!

There may also be a function that will quotemeta()characters!

Good luck with it!

- Tom


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

Date: Fri, 18 Aug 2000 14:07:46 -0700
From: "Gabe" <grichard@uci.edu>
Subject: Use of uninitialized value, but it's not uninitialized.
Message-Id: <8nk8t0$473$1@news.service.uci.edu>

I'm getting the following error:

Use of uninitialized value at parsehtml.pl line 83.

My code is:
sub ID {
    my $id; # Here the value is initialized, no?
    unless (@_) {
        ID: {
            for (my $i; $i<10; $i++) {
            $id .= int(rand 9);
            }
        }
    }
    else {
        my $table = $_[0];
        my $idfield = $_[1];
        my $dbh = $_[2];
        my $getids = $dbh->prepare(qq{SELECT $idfield FROM $table});
        $getids->execute;
        ID: {
            for (my $i; $i<10; $i++) { #This is line 83
                $id .= int(rand 9);
            }
           while (my @row = $getids->fetchrow_array) {
                if (@row eq $id) { redo ID;}
            }
        }
     }
     return $id;
}





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

Date: Fri, 18 Aug 2000 21:44:58 GMT
From: decklin+usenet@red-bean.com (Decklin Foster)
Subject: Re: Use of uninitialized value, but it's not uninitialized.
Message-Id: <u7in5.1578$CW2.11776@news1.rdc1.ct.home.com>

Gabe <grichard@uci.edu> writes:

>     my $id; # Here the value is initialized, no?

No. Same goes for $i below.

>         ID: {
>             for (my $i; $i<10; $i++) {
>             $id .= int(rand 9);
>             }
>         }

That's a very odd way of going about it.

  my $id = sprintf "%010d", rand 10_000_000_000;

But if your system won't generate random numbers that big (you have
32-bit ints, for example), you can work around it with

  my $id = sprintf "%05d%05d\n", rand 100_000, rand 100_000;

-- 
There is no TRUTH. There is no REALITY. There is no CONSISTENCY. There
are no ABSOLUTE STATEMENTS. I'm very probably wrong. -- BSD fortune(6)


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

Date: Fri, 18 Aug 2000 14:19:20 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: We Need Your Feedback
Message-Id: <399D8C38.6F1CCCAF@rac.ray.com>

waseema@my-deja.com wrote:
> 
> Hi
> 
> We are currently at the very end of the developemnt of a brand new IT
> site , covering every issue to do with the this vast medium of
> communication and business.
> 

It's not particularly a "brand new" concept.

And I have a hard time taking seriously any site that uses kewl caps.

	viz:  aRe yoU reaDy ?

I guess I'm not.

ps: Your TheCounter.com link is busted. I guess you're not either.

pps: I think the cmos battery on your pc is dead, it's already way
past "early 2000."

ppps: Why do you use frames on that page? (I really don't want to
know, I'm just showing up your shortcomings before Abigail gets her
mitts on you.

pppps: I did like the white on blue text, though.

That's a lot of pee-pee, ain't it Drew?

-- 
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747

Quae narravi, nullo modo negabo. - Catullus


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

Date: Fri, 18 Aug 2000 20:58:56 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: We Need Your Feedback
Message-Id: <8nk824$pjj$1@nnrp1.deja.com>

What the hell, it's already off-topic, let's keep rollin'..

In article <399D8C38.6F1CCCAF@rac.ray.com>,
  Russ Jones <russ_jones@rac.ray.com> wrote:
> waseema@my-deja.com wrote:
> >
> > Hi
> >
> > We are currently at the very end of the developemnt of a brand new
IT
> > site , covering every issue to do with the this vast medium of
> > communication and business.
> >
>
> It's not particularly a "brand new" concept.
>
> And I have a hard time taking seriously any site that uses kewl caps.
>
> 	viz:  aRe yoU reaDy ?
Concur, wholeheartedly...

>
> I guess I'm not.
>
> ps: Your TheCounter.com link is busted. I guess you're not either.
Heh-heh!

>
> pps: I think the cmos battery on your pc is dead, it's already way
> past "early 2000."
We're doing the TimeWarp...
>
> ppps: Why do you use frames on that page? (I really don't want to
> know, I'm just showing up your shortcomings before Abigail gets her
> mitts on you.
You got frames?  Did he fix it, or do they have some kind of cool DHTML
engine, that selectively generates frames?

>
> pppps: I did like the white on blue text, though.
Well... Opinion is just that...

>
> That's a lot of pee-pee, ain't it Drew?
>
Let's not stop at number 1, lets for some number 2:
Try looking at it with Netscape Navigator on NT.  All I got was the "aRe
yoU reaDy ?" and I had to try it with $@#@^&@*($$@#(ing MSIE.
Personally, if it wont display in Navigator, I've got no use for it.
Total crap.  Wonder what Lynx will do with it...

> --
> Russ Jones - HP OpenView IT/Operatons support
> Raytheon Aircraft Company, Wichita KS
> russ_jones@rac.ray.com 316-676-0747

amonotod

--
    `\|||/                     amonotod@
      (@@)                     netscape.net
  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 18 Aug 2000 12:22:08 -0400
From: Steve Alpert <Steve_Alpert@idx.com>
Subject: Re: Win2K; Perl from command line
Message-Id: <bhpqpso5bqavucf85ibt42ortqrh2e6gmd@4ax.com>

"Michael Weir" <mweir@jetform.com> wrote:

>Is there a way to invoke perl the way you do batch files?  So instead of
>typing 'perl myCmd.pl' I could just type 'myCmd' on the command line?
>
>Thanks

I believe the real answer (besides associating the file type with Perl) is to
create/modify the environment variable PATHEXT:

PATHEXT=.PL;.COM;.EXE;.BAT;.CMD

and, as was mentioned:

E:\>ftype perl
perl=D:\Perl\bin\Perl.exe "%1" %*

E:\>assoc .pl
 .pl=Perl

/steve

        Steve Alpert (Steve_Alpert @ i d x . c o m)
        IDX Systems Corp.   Boston, Massachusetts



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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4061
**************************************


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