[28171] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9535 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 28 18:05:42 2006

Date: Fri, 28 Jul 2006 15:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 28 Jul 2006     Volume: 10 Number: 9535

Today's topics:
        adding a string ~300 times <bootiack@yahoo.com>
    Re: adding a string ~300 times axel@white-eagle.invalid.uk
    Re: adding a string ~300 times <bik.mido@tiscalinet.it>
    Re: adding a string ~300 times <bootiack@yahoo.com>
    Re: adding a string ~300 times <bootiack@yahoo.com>
        Efficiently convert characters to octal representation <worky.workerson@gmail.com>
    Re: Efficiently convert characters to octal representat <worky.workerson@gmail.com>
    Re: Efficiently convert characters to octal representat <DJStunks@gmail.com>
    Re: Efficiently convert characters to octal representat <benmorrow@tiscali.co.uk>
    Re: Efficiently convert characters to octal representat <worky.workerson@gmail.com>
    Re: Efficiently convert characters to octal representat <worky.workerson@gmail.com>
    Re: Efficiently convert characters to octal representat xhoster@gmail.com
        Improving performance of a simple Perl script vfoley@gmail.com
    Re: libwww-POST Issue <azstyx@yahoo.com>
    Re: libwww-POST Issue <benmorrow@tiscali.co.uk>
    Re: libwww-SSL UserAgent Post Issue <azstyx@yahoo.com>
        Problem with perl script and form Songhw@gmail.com
        Problem with perl script and form Songhw@gmail.com
    Re: Questions about (non-blocking) sockets <spam.trap.never.read@mailinator.com>
        same code diff result <Amaninder.Saini@gmail.com>
        STOP what you’re doing - It doesn’t work! IU49 iujyrojt@email.adr
    Re: Sybase connection error <DJStunks@gmail.com>
        Text::ParseWords::parse_line bug? <alexbasa@gmail.com>
    Re: Text::ParseWords::parse_line bug? xhoster@gmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 28 Jul 2006 13:29:58 -0700
From: "gavino" <bootiack@yahoo.com>
Subject: adding a string ~300 times
Message-Id: <1154118598.068578.90730@m79g2000cwm.googlegroups.com>

I have a dns config file named.conf I need to reconfigure to enable a
slave dns server.

It involves making

        zone "pims.teampcs.com" {
                type slave;
                file
"internal/pcs/master/pims.teampcs.com.zone.internal.bak";
        };


look like

        zone "pims.teampcs.com" {
                type slave;
                file
"internal/pcs/master/pims.teampcs.com.zone.internal.bak";
                masters { 172.16.100.11; };
        };

I don't know how to do this in vi since it involves adding a string on
a new line below each occourance of .bak";

how would a perler add that line below each instance of .bak"; ?



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

Date: Fri, 28 Jul 2006 20:52:56 GMT
From: axel@white-eagle.invalid.uk
Subject: Re: adding a string ~300 times
Message-Id: <IOuyg.7315$5K2.5116@fed1read03>

gavino <bootiack@yahoo.com> wrote:
> I have a dns config file named.conf I need to reconfigure to enable a
> slave dns server.
> 
> It involves making
> 
>        zone "pims.teampcs.com" {
>                type slave;
>                file
> "internal/pcs/master/pims.teampcs.com.zone.internal.bak";
>        };
> 
> 
> look like
> 
>        zone "pims.teampcs.com" {
>                type slave;
>                file
> "internal/pcs/master/pims.teampcs.com.zone.internal.bak";
>                masters { 172.16.100.11; };
>        };
> 
> I don't know how to do this in vi since it involves adding a string on
> a new line below each occourance of .bak";

:1,$s/\(internal.bak.*$\)/\1^V^M                masters { 172.16.100.11; }; ^V^M
 
> how would a perler add that line below each instance of .bak"; ?

Read in the file and after each line containing 'internal.bak add
the required additional line to the output.

Axel




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

Date: 28 Jul 2006 23:15:06 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: adding a string ~300 times
Message-Id: <lhvkc2lsfd0n1vg88t6ljp5jgscfpcpq8d@4ax.com>

On 28 Jul 2006 13:29:58 -0700, "gavino" <bootiack@yahoo.com> wrote:

>how would a perler add that line below each instance of .bak"; ?

perl -lpi -e '$_ .= "\nadded_line" if /\.bak";$/'


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


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

Date: 28 Jul 2006 14:49:46 -0700
From: "gavino" <bootiack@yahoo.com>
Subject: Re: adding a string ~300 times
Message-Id: <1154123386.219284.288430@p79g2000cwp.googlegroups.com>

How would I run that perl code if the file is called
named.conf.testing?
Is that a tab in the middle of the code?
also internal.bak is not unique, there is also external.bak so I guess
I change it to

:1,$s/\(internal.bak.*$\)/\1^V^M masters { 172.16.100.11; }; ^V^M

axel@white-eagle.invalid.uk wrote:
> gavino <bootiack@yahoo.com> wrote:
> > I have a dns config file named.conf I need to reconfigure to enable a
> > slave dns server.
> >
> > It involves making
> >
> >        zone "pims.teampcs.com" {
> >                type slave;
> >                file
> > "internal/pcs/master/pims.teampcs.com.zone.internal.bak";
> >        };
> >
> >
> > look like
> >
> >        zone "pims.teampcs.com" {
> >                type slave;
> >                file
> > "internal/pcs/master/pims.teampcs.com.zone.internal.bak";
> >                masters { 172.16.100.11; };
> >        };
> >
> > I don't know how to do this in vi since it involves adding a string on
> > a new line below each occourance of .bak";
>
> :1,$s/\(internal.bak.*$\)/\1^V^M                masters { 172.16.100.11; }; ^V^M
>
> > how would a perler add that line below each instance of .bak"; ?
>
> Read in the file and after each line containing 'internal.bak add
> the required additional line to the output.
> 
> Axel



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

Date: 28 Jul 2006 14:51:40 -0700
From: "gavino" <bootiack@yahoo.com>
Subject: Re: adding a string ~300 times
Message-Id: <1154123500.014411.250300@m73g2000cwd.googlegroups.com>

substitute added_line for the new line?
if the file to be changed is called named.conf.testing how would the
command look?

Michele Dondi wrote:
> On 28 Jul 2006 13:29:58 -0700, "gavino" <bootiack@yahoo.com> wrote:
>
> >how would a perler add that line below each instance of .bak"; ?
> 
> perl -lpi -e '$_ .= "\nadded_line" if /\.bak";$/'
> 
> 
> Michele



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

Date: 28 Jul 2006 11:54:20 -0700
From: "Worky Workerson" <worky.workerson@gmail.com>
Subject: Efficiently convert characters to octal representation
Message-Id: <1154112860.643013.308990@i42g2000cwa.googlegroups.com>

I have a (possibly binary) string like "worky" where I'd like to
convert each byte to its octal representation, resulting in a string
"\167\157\162\153\171".  I have two solutions, however I'm looking for
any way that would be faster.

Control:
  $content = 'worky';
  return $content;

Solution 1 (in place w/regex):
  $content = 'worky';
  $content =~ s/(.|\n)/sprintf("\\%03o", ord $1)/eg;
  return $content

Solution 2 (index into string):
  $content = 'worky';
  do {
    use bytes;
    foreach my $idx (0..(length($content)-1)) {
      $ret .= sprintf("\\%03o", ord(substr($content, $idx, 1)));
    }
  };
  return $ret;

Based on a quick cmpthese benchmark, the control is about 16 times
faster than solution 1 and about 9 times faster than solution 2.

Does anyone know of A) The fastest way to do this or B) some
tips/tricks on how to speedup my methods?

Thanks!
-Worky



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

Date: 28 Jul 2006 12:35:12 -0700
From: "Worky Workerson" <worky.workerson@gmail.com>
Subject: Re: Efficiently convert characters to octal representation
Message-Id: <1154115312.602708.14910@i3g2000cwc.googlegroups.com>

After tinkering for a while, my best solution is now:
  $content = 'worky'
  return join('', map {sprintf("\\%03o", $_)} unpack("C*", $content));

Anyone got anything better?

Thanks!
-Worky



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

Date: 28 Jul 2006 12:48:24 -0700
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: Efficiently convert characters to octal representation
Message-Id: <1154116104.002358.311490@i42g2000cwa.googlegroups.com>

Worky Workerson wrote:
> I have a (possibly binary) string like "worky" where I'd like to
> convert each byte to its octal representation, resulting in a string
> "\167\157\162\153\171".  I have two solutions, however I'm looking for
> any way that would be faster.
>
> Control:
>   $content = 'worky';
>   return $content;
>
> Solution 1 (in place w/regex):
>   $content = 'worky';
>   $content =~ s/(.|\n)/sprintf("\\%03o", ord $1)/eg;
>   return $content
>
> Solution 2 (index into string):
>   $content = 'worky';
>   do {
>     use bytes;
>     foreach my $idx (0..(length($content)-1)) {
>       $ret .= sprintf("\\%03o", ord(substr($content, $idx, 1)));
>     }
>   };
>   return $ret;
>
> Based on a quick cmpthese benchmark, the control is about 16 times
> faster than solution 1 and about 9 times faster than solution 2.
>
> Does anyone know of A) The fastest way to do this or B) some
> tips/tricks on how to speedup my methods?

if you have the benchmark set up, try this sub:

  #!/usr/bin/perl

  use strict;
  use warnings;

  my $string = 'worky';
  print convert_to_octal($string);

  sub convert_to_octal {
  	my ($string) = @_;

 	return map { sprintf '\\%03o', ord $_ }
  	       split //, $string;
  	
  }
  
  __END__

-jp



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

Date: Fri, 28 Jul 2006 21:35:09 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Efficiently convert characters to octal representation
Message-Id: <t09qp3-g8t.ln1@osiris.mauzo.dyndns.org>


Quoth "Worky Workerson" <worky.workerson@gmail.com>:

[please quote some context when you reply. Have you read the Posting
Guidelines?]

[converting a string into octal esacpes]

> After tinkering for a while, my best solution is now:
>   $content = 'worky'
>   return join('', map {sprintf("\\%03o", $_)} unpack("C*", $content));
> 
> Anyone got anything better?

Here's a couple more, in the spirit of TMTOWTDI:

#!/usr/bin/perl

use warnings;
use strict;
use Math::BaseCnv;
use Benchmark qw/cmpthese/;

$\ = "\n";
my $w = 'worky';

my %subs = (
    regex  => sub { (my $x = $w) =~ s/(.)/sprintf '\\%3o', ord $1/egs; $x; },
    substr => sub {
        use bytes;
        my $x;
        for (0..(length $w) - 1) {
            $x .= sprintf '\\%3o', ord substr $w, $_, 1;
        }
        return $x;
    },
    unpack => sub { join '', map sprintf('\\%3o', $_), unpack 'C*', $w },
    split  => sub { 
        use bytes;
        join '', map sprintf('\\%3o', ord), split //, $w
    },
    cnv    => sub { '\\' . join '\\', map cnv($_, 10, 8), unpack 'C*', $w; },
);

for (keys %subs) {
    print "$_ => " . $subs{$_}->();
}

cmpthese -3, \%subs;

__END__

This gives (on my machine)

cnv => \167\157\162\153\171
regex => \167\157\162\153\171
unpack => \167\157\162\153\171
substr => \167\157\162\153\171
split => \167\157\162\153\171
          Rate    cnv  regex  split unpack substr
cnv     5618/s     --   -87%   -87%   -92%   -92%
regex  42639/s   659%     --    -0%   -39%   -39%
split  42712/s   660%     0%     --   -39%   -39%
unpack 69589/s  1139%    63%    63%     --    -1%
substr 70257/s  1151%    65%    64%     1%     --

This is usually true: substr > unpack > split > regex. The reason is
that Perl ops are so much slower than C.

However, I am hard-pressed to think of a situation where it's worth
writing anything other than 'regex' above, as clarity is almost always
more important than speed.

Also note that the 'regex' solution would need a 'use bytes' to be
strictly compatible with the others. I'm not sure why you think you need
it: if you've read your data from a binmode :raw filehandle it's binary
anyway; otherwise you want to encode it with Encode into a suitable
encoding.

Ben

-- 
  Joy and Woe are woven fine,
  A Clothing for the Soul divine       William Blake
  Under every grief and pine          'Auguries of Innocence'
  Runs a joy with silken twine.                         benmorrow@tiscali.co.uk


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

Date: 28 Jul 2006 13:41:13 -0700
From: "Worky Workerson" <worky.workerson@gmail.com>
Subject: Re: Efficiently convert characters to octal representation
Message-Id: <1154119272.982364.109410@i3g2000cwc.googlegroups.com>

>   sub convert_to_octal {
>   	my ($string) = @_;
>
>  	return map { sprintf '\\%03o', ord $_ }
>   	       split //, $string;
>
>   }

Its about 25% slower than my "best" solution listed previously, which
was basically the same thing with unpack instead of split.  Also, since
the data might be binary, I'm worried about the split // ... isn't that
a character split (vs a binary split)?



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

Date: 28 Jul 2006 14:03:11 -0700
From: "Worky Workerson" <worky.workerson@gmail.com>
Subject: Re: Efficiently convert characters to octal representation
Message-Id: <1154120591.330761.3040@p79g2000cwp.googlegroups.com>

Ben Morrow wrote:
> [converting a string into octal esacpes]
>
> my %subs = (
>     regex  => sub { (my $x = $w) =~ s/(.)/sprintf '\\%3o', ord $1/egs; $x; },
>     substr => sub {
>         use bytes;
>         my $x;
>         for (0..(length $w) - 1) {
>             $x .= sprintf '\\%3o', ord substr $w, $_, 1;
>         }
>         return $x;
>     },
>     unpack => sub { join '', map sprintf('\\%3o', $_), unpack 'C*', $w },
>     split  => sub {
>         use bytes;
>         join '', map sprintf('\\%3o', ord), split //, $w
>     },
>     cnv    => sub { '\\' . join '\\', map cnv($_, 10, 8), unpack 'C*', $w; },
> );

> However, I am hard-pressed to think of a situation where it's worth
> writing anything other than 'regex' above, as clarity is almost always
> more important than speed.

I'm doing database ETL and transforming 300GB of CSV into something the
database likes to load.  According to DProf, this was my biggest
slacker by far, partly because it is called so often.  Every little bit
of speed helps :)

> Also note that the 'regex' solution would need a 'use bytes' to be
> strictly compatible with the others. I'm not sure why you think you need
> it: if you've read your data from a binmode :raw filehandle it's binary
> anyway; otherwise you want to encode it with Encode into a suitable
> encoding.

I guess I'm still a little fuzzy on the whole perl/binary thing.  I'm
reading in CSV where most of the columns are ASCII but I'm not sure
what sort of data will be stored in one of the columns.  I am declaring
binmode on the filehandle ... do I still need the 'use bytes' on the
substr approach?



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

Date: 28 Jul 2006 21:18:27 GMT
From: xhoster@gmail.com
Subject: Re: Efficiently convert characters to octal representation
Message-Id: <20060728172532.560$3F@newsreader.com>

"Worky Workerson" <worky.workerson@gmail.com> wrote:
> I have a (possibly binary) string like "worky" where I'd like to
> convert each byte to its octal representation, resulting in a string
> "\167\157\162\153\171".  I have two solutions, however I'm looking for
> any way that would be faster.
>
 ...
> Solution 2 (index into string):
>   $content = 'worky';
>   do {
>     use bytes;
>     foreach my $idx (0..(length($content)-1)) {
>       $ret .= sprintf("\\%03o", ord(substr($content, $idx, 1)));
>     }
>   };
>   return $ret;
 ...
> Does anyone know of A) The fastest way to do this or B) some
> tips/tricks on how to speedup my methods?

This seems like a pretty strange thing to need to optimize.  How many
times do you need to do this operation on a 5 character fixed string?
If you don't need to do it on a 5 character fixed string, then your
benchmark should incorporate realistic sizes and with more realistic
methods for obtaining the non-fixed thing you want to operate on.

Anyway, if really need the speed, this Inline C code is about 3 times
faster than sol2.

              Rate     sol1     sol2     sol3 control2
sol1       70274/s       --     -45%     -82%     -94%
sol2      127219/s      81%       --     -67%     -89%
sol3      385820/s     449%     203%       --     -66%
control2 1122504/s    1497%     782%     191%       --


Benchmark::cmpthese(-5, {
               'control' => sub {control($text)},
               'sol1' => sub {sol1($text)},
               'sol2' => sub {sol2($text)},
               'sol3' => sub {sol3($text)},
           });
__END__
__C__
SV* sol3(SV* a) {
  STRLEN len;
  int i;
  unsigned char * s;
  SV* ret;
  s = SvPV(a,len);
  ret = newSV(4*len);
  for (i=0; i<len; i++,s++) {
    sv_catpvf(ret, "\\%03o", *s);
  };
  return ret;
};


Xho

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


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

Date: 28 Jul 2006 14:20:25 -0700
From: vfoley@gmail.com
Subject: Improving performance of a simple Perl script
Message-Id: <1154121624.651703.136330@h48g2000cwc.googlegroups.com>

Hello everyone,

I wrote a little script in Perl to make stats on a log file.  You can
view the source at: http://pastebin.ca/104391 .  When running on an
OpenBSD 3.9 machine (Pentium III 450 MHz, 128 MB RAM), with Perl 5.8.6,
the script takes 35 seconds to crunch through a file with 175,000
lines.  Not bad.  However, a Ruby script (http://pastebin.ca/104393)
that I wrote a while ago does the same file in 23 seconds.  As far as I
know, the Perl interpreter is faster than Ruby, so I would be
interested to know how I could improve the execution speed of the Perl
script.  I'm still very new, so I don't know all the idioms and such,
so any help would be greatly appreciated.

Also, when I profiled the Perl script, dprofpp's time percentages only
added up to like 5 or 10%.  Why is that?  Where is the remaining 90%?

Regards,

Vincent



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

Date: 28 Jul 2006 11:48:11 -0700
From: "AZSTYX" <azstyx@yahoo.com>
Subject: Re: libwww-POST Issue
Message-Id: <1154112491.823649.135740@p79g2000cwp.googlegroups.com>


AZSTYX wrote:
> Hello Folks!
>
> Environment:
> libwww-perl: 5.805
> OS: Solaris 8
> Perl: 5.8.4
>
> Issue Summary:
> Issue with posting form variables in POST operation using
> HTTP::REQUEST.
>
> I have a script that sends a form via POST with one form element
> 'DownloadFormat=ascii'.
> I first wrote the script using pure UserAgent POST and all works fine.
> However, I tried (just for a learning experience) to utilize
> HTTPS::Request method
>  and I have an unexplained issue.
> According to the lwpcook.pod, they give an example:
> HTTP::REQUEST example format:
> [code]
> my $req = HTTP::Request->new(POST =>
> 'http://www.perl.com/cgi-bin/BugGlimpse');
>   $req->content_type('application/x-www-form-urlencoded');
>   $req->content('match=www&errors=0');
> my $res = $ua->request($req);
> [/code]
> UserAgent POST example format:
> [code]
> my $req = POST 'http://www.perl.com/cgi-bin/BugGlimpse',
>                 [ search => 'www', errors => 0 ];
>
>   print $ua->request($req)->as_string;
> [/code]
>
> In reviewing this info, I see that the author is passing the form
> variables and
> values in the ::REQUEST via the $req->content(). I am not understanding
> this call
>  of why the form varaibles would be passed in the content section?
> Especially in
>  the next example when they use the variable 'search" and in the first
> example
>   they use the variable 'match' (I guess thats another question?)
>
> The only way I was able to get the script to work properly was to code
> the
>  single form variable and value ('DownloadFormat=ascii') in the URL as:
> https://10.10.10.10:1954/dynamic/File/Configuration/ReceivefromDevice?DownloadFormat=ascii
> AND I also HAD TO specify something (didn't seem to matter what) in the
> content() method.
>  To make it work I used some garbage text: $httpReq->
> content('Comment=justacomment') ;
>
>  Q: Why did I have to pass my form variable and value like I would if I
> was doing a GET,
>  when I am doing a form POST operation?
>  (I prefixed my URL with '?DownloadFormat=ascii').
>  Q: What is the proper method using HTTP::REQUEST to pass form
> variables and values when
>  doing a POST operation?
>  Q: Why did I have to specify something in content(), even though it
> was just garbage code?
>  ($httpReq-> content('Comment=justacomment') ;)(It would not work
> otherwise!)
>
>  My script:
>
>  [code]
>  #!/export/ieapps/common/perl5/perl-5.8.4/bin/perl
> # getwsd3.pl - LWP demo - downloads a radware WSD config ascii file.
> # utilizes HTTPS and login credentials, https request object
> # interfacing with https request object is depreciated form
> # usage: lwpdemo.pl <devname> <devipaddr> <port> <uid> <passw>
> # output: /export/ieapps/local/test/<devName.asc>
> use strict;
> use warnings;
> use LWP;
> #############################################
> my $urlConfigFile = '/dynamic/File/Configuration/ReceivefromDevice' ;
> my $urlDeviceinfo = '/dynamic/Device/DeviceInformation';
> my ($ua, $httpReq, $httpResp, $url, $baseUrl, $credUrl, $strReq);
> my ($devName, $devIP, $port, $UID, $upassw);
> my ($statusLine, $statusCode, $statusMsg, $contentResponse);
> my $asciiFile = "/export/ieapps/local/test/";
>
>
> #################################################
>
> if (@ARGV == 5) {		# if there are 5 arguments
> 	$devName = $ARGV[0];
> 	$devIP = $ARGV[1];
> 	$port = $ARGV[2];
> 	$UID = $ARGV[3];
> 	$upassw = $ARGV[4];
> }
> else {
> 	die "Error 01:  Usage: $0 <devname> <devipaddr> <port> <uid>
> <passw>\n";
> }
> print "Processing devName [$devName] ip addr [$devIP].\n";
> print "Using libwww-perl-$LWP::VERSION\n";
> $asciiFile .= "$devName.asc";
> print "Output file is [$asciiFile].\n";
> $baseUrl = "https://$devIP:$port";			# create base URL
> $credUrl = "$devIP:$port";					# create URL for credentials
> print "Base URL [$baseUrl]\n";
> #######################################################################
> # start LWP Processing
> #########################################################################
> $ua = LWP::UserAgent->new;				# create new user agent object
> $ua->timeout(15);						# set user agent timeout to 15 seconds
> $url = "$baseUrl$urlConfigFile?DownloadFormat=ascii";		# create URL for
> getting config ascii file
>
> # set up HTTP REQUEST object
> $httpReq = HTTP::Request->new(POST=>$url) ;			# init Request object
> $httpReq-> content_type('multipart/form-data') ;	# content type/mode
> $httpReq-> content('Comment=justacomment') ;		# content garbage to make
> it work
> $httpReq-> authorization_basic($UID, $upassw) ;		# credentials
> $strReq = $httpReq->as_string( );
> print "\nThe Request:\n$strReq\n";
> print "\n\nNow get the WSD config ascii file.\n";
> print "Submitting browser request using url [$url].\n";
> $httpResp = $ua->request($httpReq) ;
>
> $statusLine = $httpResp->status_line();
> $statusCode = $httpResp->code();
> $statusMsg = $httpResp->message();
> print "HTTP Response: StatusLine[$statusLine] Code[$statusCode]
> Message[$statusMsg]\n";
> if ($httpResp->is_success) {
> 	print "Request OK.\n";
> }
> else {
> 	die "Request failed.\n";
> }
> # ok, save content to file
> open(FILEO, ">$asciiFile") || die "Error $! Could not open file
> $asciiFile.\n";
> print FILEO $httpResp->content;
> close(FILEO);
>
>
>  [/code]
>
>
>  The run results:
>
>  [code]
>  dsysadm03z>./getwsd3.pl device-y 10.10.10.10 1900 admin admin
> Processing devName [device-y] ip addr [10.10.10.10].
> Using libwww-perl-5.805
> Output file is [/export/ieapps/local/test/device-y.asc].
> Base URL [https://10.10.10.10:1900]
>
> The Request:
> POST
> https://10.10.10.10:1900/dynamic/File/Configuration/ReceivefromDevice?DownloadFormat=ascii
> Authorization: Basic aWVhZG1pbjptMWdodHkhTTB1czM=
> Content-Type: multipart/form-data
>
> Comment=justacomment
>
>
>
> Now get the WSD config ascii file.
> Submitting browser request using url
> [https://10.10.10.10:1900/dynamic/File/Configuration/ReceivefromDevice?DownloadFormat=ascii].
> HTTP Response: StatusLine[200 OK] Code[200] Message[OK]
> Request OK.
> dsysadm03z>
>
>  [/code]
>
>  Appreciate any feedback anyone may have to offer!!!
>  :)
>  styx


RESOLVED!!
When using this method, code form varaibles in ->content().
Do not use $httpReq-> content_type('multipart/form-data') ; that is
only for uploading files.
For post do not inlcue variables in URL.
New code that works:
[code]
$url=dynamic/File/Configuration/ReceivefromDevice
$httpReq = HTTP::Request->new(POST=>$url) ;			# init Request object
$httpReq->content('DownloadFormat=ascii');			# pass form variables
$httpReq-> authorization_basic($UID, $upassw) ;		# credentials
$httpResp = $ua->request($httpReq) ;


[/code]



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

Date: Fri, 28 Jul 2006 20:42:18 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: libwww-POST Issue
Message-Id: <qt5qp3-okf.ln1@osiris.mauzo.dyndns.org>


Quoth "AZSTYX" <azstyx@yahoo.com>:
> 
> AZSTYX wrote:
> > According to the lwpcook.pod, they give an example:
> > HTTP::REQUEST example format:
> > [code]
> > my $req = HTTP::Request->new(POST =>
> > 'http://www.perl.com/cgi-bin/BugGlimpse');
> >   $req->content_type('application/x-www-form-urlencoded');
> >   $req->content('match=www&errors=0');
> > my $res = $ua->request($req);
> > [/code]

<snip>

> > #######################################################################
> > # start LWP Processing
> > #########################################################################
> > $ua = LWP::UserAgent->new;				# create new user agent object
> > $ua->timeout(15);						# set user agent timeout to 15 seconds
> > $url = "$baseUrl$urlConfigFile?DownloadFormat=ascii";		# create URL for
> > getting config ascii file
> >
> > # set up HTTP REQUEST object
> > $httpReq = HTTP::Request->new(POST=>$url) ;			# init Request object
> > $httpReq-> content_type('multipart/form-data') ;	# content type/mode

<snip>

> RESOLVED!!
> When using this method, code form varaibles in ->content().
> Do not use $httpReq-> content_type('multipart/form-data') ; that is
> only for uploading files.

No, when using multipart/form-data, make sure the POSTs body is actually
formatted as multipart/form-data. You can't just randomly change the
content-type and expect things to work.

> For post do not inlcue variables in URL.

There are situations where POSTing to a URL including a query-string is
sensible, however they are rare, and do not arise from ordinary form
submission.

Ben

-- 
Giles: It's very common for Indian spirits to change to animal form.
Buffy: [...] and, 'Native American'. G: Sorry? B: We don't say 'Indian'.
G: Oh, right, yes; always behind on the terms... yes, still trying not to refer
to you lot as 'bloody colonials'.      [Buffy, 'Pangs'] benmorrow@tiscali.co.uk


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

Date: 28 Jul 2006 11:54:01 -0700
From: "AZSTYX" <azstyx@yahoo.com>
Subject: Re: libwww-SSL UserAgent Post Issue
Message-Id: <1154112841.814743.265080@75g2000cwc.googlegroups.com>


Dr.Ruud wrote:
> AZSTYX schreef:
>
> > $ua->timeout(15); # set user agent timeout to 15 seconds
>
> Did you test with 30 or 60?
>
> --
> Affijn, Ruud
>
> "Gewoon is een tijger."

Hello, thx for the reply and info!
:)
Yes, I just tried with timeout(30) and 60 and got the same results.
thx,
Styx



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

Date: 28 Jul 2006 15:01:09 -0700
From: Songhw@gmail.com
Subject: Problem with perl script and form
Message-Id: <1154124069.019274.313390@m79g2000cwm.googlegroups.com>

Hello,

I am try to run a  Perl script from a form. I tested both the form and
the script seperatlly. they are fine. But when I put them together, the
IE was not runing the script but giving me a alert messagebox let to
choose if I will open it or download it. if I choose open, the script
will be run in the dos mode and return back with nothing.

Can someone tell me the steps I have to follow to run my program ?


Thanks 


HS



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

Date: 28 Jul 2006 15:01:32 -0700
From: Songhw@gmail.com
Subject: Problem with perl script and form
Message-Id: <1154124092.663382.26020@s13g2000cwa.googlegroups.com>

Hello,

I am try to run a  Perl script from a form. I tested both the form and
the script seperatlly. they are fine. But when I put them together, the
IE was not runing the script but giving me a alert messagebox let to
choose if I will open it or download it. if I choose open, the script
will be run in the dos mode and return back with nothing.

Can someone tell me the steps I have to follow to run my program ?


Thanks 


HS



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

Date: Fri, 28 Jul 2006 21:00:54 +0200
From: Holger <spam.trap.never.read@mailinator.com>
Subject: Re: Questions about (non-blocking) sockets
Message-Id: <44ca5e0f.25328004@news.arcor.de>

On 28 Jul 2006 15:57:58 GMT, xhoster@gmail.com wrote:
> I don't think that that is what I was trying to describe.  The server is
> not blocking on read, it is blocking on write (waiting for the client to
> read).  In other words, it is trying to keep sending, but the client won't
> read what it is writing and the buffer is full, so its attempt at sending
> blocks.

Ah, ok. Misunderstood before.

> > Hmm, how would I actually test this? Syswrite something
> > without a record separator and then try to read?
> 
> Don't try to read at all, just keep writing.  syswrite or print, doesn't
> matter but print is easier, and you may as well use a record separator
> (otherwise you would be testing something different).  If the server uses
> blocking writes to you, then eventually the server will block on its write
> to you, and hence stop reading what you write to it, and then you will
> block on writing to it, resulting in a deadlock.

Thanks. I'll try this.

Regards,

	Holger


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

Date: 28 Jul 2006 13:29:24 -0700
From: "Amaninder" <Amaninder.Saini@gmail.com>
Subject: same code diff result
Message-Id: <1154118563.940801.236120@b28g2000cwb.googlegroups.com>

Hi everyone

I tried lot of things but can not able to figure out why the same code
in for loop is giving me different results.
Code 1 is giving me the correct result but Code 2 does NOT. All i am
doing in ths Code 1  is that i have
my $got  = "3        500      1660     17800    19360    N";
my $exp  = "<0 3>        <0 500>      <0 1660>     17800    19360    <0
N>";

and i am filling @btw with ('"0 3". "3", "0 500", "500",  "0 N" ,
"N").

Now the code in "Code 2" is same except it is funtion and i am
receiving $got and $exp as a parameters.

Problem is in "Code 2" $got =~ s/$split[$i]//;  deletes the content of
$got whereas in "Code 1" it does NOT when lenght of $split[$i] = 0 in
both cases.


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

sub trim($)
{
    my $string = shift;
    if (defined($string) ){
        $string =~ s/^\s+//;
        $string =~ s/\s+$//;

    }
    return $string;
}


my @btw;
my $errMess;
my $got  = "3        500      1660     17800    19360    N";
my $exp  = "<0 3>        <0 500>      <0 1660>     17800    19360    <0
N>";
my @split = split(/<|>/, $exp);


for(my $i = 0; $i <= $#split; $i=$i+2){
    if($i+1 > $#split){
        last;
    }
    push (@btw, $split[$i + 1]);
    $split[$i] = trim ($split[$i]);
    $got =~ s/$split[$i]//;

    if ( $i + 2 > $#split){
        push (@btw, $got);
    }else{
        $split[$i + 2] = trim ($split[$i + 2]);
        #in freq one if $split[$i + 2]= '    ' , then trim will delete
all the
        #space and leave it to nothing. length = 0
        #Therefore, if lenght is 0 let $split[$i + 2] = ' ', so that
$point != 0
        if( length ($split[$i + 2]) == 0){
            $split[$i + 2] = ' ';
        }
        my $point = index $got, $split[$i + 2];
        if( $point == -1){
            $errMess = sprintf ( "'%s' is NOT found", $split[$i + 2]);
            last;
        }elsif($point == 0){
            $errMess = sprintf ( ">,< should NOT be together");
            last;
        }
        push (@btw, substr $got, 0, $point, '');
        $got = trim ($got);
    }
}

foreach my $temp (@btw){
    printf ("\n%s", $temp?$temp:'');
}
printf ("\n%s.", $errMess?$errMess:'');








#####################Code 2###################################
sub compareLines{
    my $exp = shift;
    my $got = shift;
    #default is pass
    my $passOrFail = 'pass';
    my $errMess;



    my @split = split(/<|>/, $exp);
    my @btw;

    for(my $i = 0; $i <= $#split; $i=$i+2){
        if($i+1 > $#split){
            last;
        }
        push (@btw, $split[$i + 1]);
        $split[$i] = trim ($split[$i]);
        $got =~ s/$split[$i]//;

        if ( $i + 2 > $#split){
            push (@btw, $got);
        }else{
            $split[$i + 2] = trim ($split[$i + 2]);
            #in freq one if $split[$i + 2]= '    ' , then trim will
delete all the
            #space and leave it to nothing. length = 0
            #Therefore, if lenght is 0 let $split[$i + 2] = ' ', so
that $point != 0
            if( length ($split[$i + 2]) == 0){
                $split[$i + 2] = ' ';
            }
            my $point = index $got, $split[$i + 2];
            if( $point == -1){
                $errMess = sprintf ( "compareLines(): '%s' is NOT
found", $split[$i + 2]);
                last;
            }elsif($point == 0){
                $errMess = "compareLines(): >,< should NOT be
together";
                last;
            }
            push (@btw, substr $got, 0, $point, '');
            $got = trim ($got);
        }
    }

    #if there is any error return
    if( defined ($errMess) && $errMess =~ /.+/){
        return ($errMess, $passOrFail);
    }

    #send to compare elements in the array
    ($errMess, $passOrFail) = compareElemArray(\@btw);

    if( defined ($errMess) && $errMess =~ /.+/){
        # add compareLines
        $errMess = "compareLines(): $errMess";
    }
    
    return ($errMess, $passOrFail);
}


Regards
Amaninder Saini  :)



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

Date: Fri, 28 Jul 2006 21:30:47 GMT
From: iujyrojt@email.adr
Subject: STOP what you’re doing - It doesn’t work! IU49
Message-Id: <bmvyg.82005$sz1.31496@newsfe6-gui.ntli.net>



Always staying on the cutting edge of the latest trends and effective advertising methods,
Kiosk offers only the best and time worthy promotional tools. 
If we don't have it, you don't need it!

*Supersponder

*Prospecting system

*Master Profit system

*Promotional pages

*Complete resell rights for our library of proprietary products

*Ad tracking

*Membership to our safelist franchise

*Super FFA system

*Group Networking


Click below to find out what has the super-affiliates
quaking in their boots


http://tinyurl.com/pzkxe


Thank you for your time, and we wish you a profitable 2006!

Regards,
Clive Foster

Please visit the following site, for the best promotional
and marketing idea we have seen this year:


http://tinyurl.com/pzkxe


---

Nese desacawet so diseb bo tobenifonod calihomed tib nif lomapadak cerefidacem rot berinesa xolamup .



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

Date: 28 Jul 2006 12:18:51 -0700
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: Sybase connection error
Message-Id: <1154114331.857085.234590@i3g2000cwc.googlegroups.com>

lnatz wrote:
> Hi I am having a problem with this line of code:
>  $DBH =
>     DBI->connect("dbi:Sybase:server=$dbserver", $dbuser, $dbpassword)
>       || die "$DBI::errstr";
>   $DBH->do("use $database");
>
> I am getting this error when executing:
> DBI connect('server=NYT_LIBRAONLINE','natrabi
> ',...) failed: Server message number=4002 severity=14 state=1 line=0
> server=NYTINV3T002 text=Login failed.
> OpenClient message: LAYER = (4) ORIGIN = (1) SEVERITY = (4) NUMBER =
> (44)
> Server NYT_LIBRAONLINE, database
> Message String: ct_connect(): protocol specific layer: external error:
> The attempt to connect to the server failed.
>  at ./purge.pl line 45
> Server message number=4002 severity=14 state=1 line=0
> server=NYTINV3T002 text=Login failed.
> OpenClient message: LAYER = (4) ORIGIN = (1) SEVERITY = (4) NUMBER =
> (44)
> Server NYT_LIBRAONLINE, database
> Message String: ct_connect(): protocol specific layer: external error:
> The attempt to connect to the server failed.
>
>
> Basically I am trying to connect to Sybase and I can't figure out what
> I am missing.

I would say this is an authentication problem:

http://manuals.sybase.com/onlinebooks/group-as/asg1250e/svrtsg/@Generic__BookTextView/39367;pt=39281/*

-jp



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

Date: 28 Jul 2006 11:31:25 -0700
From: "tsotsi" <alexbasa@gmail.com>
Subject: Text::ParseWords::parse_line bug?
Message-Id: <1154111485.510717.218070@m73g2000cwd.googlegroups.com>

Does anyone know of any bug in ParseWords?  I have an input string that
I want to split on the pipe using ParseWords since split removes
trailing pipes with empty data.

code
---------------------------------------------------------------------------------------------------------------------
use Text::ParseWords;

open(INPUT,"testdata.txt");

while (<INPUT>)
    {
    chomp;
    my @fields = Text::ParseWords::parse_line( qr(\|), 0,$_);
    print "==$_==\n";
    print "field0=$fields[0]\n";
    print "field1=$fields[0]\n";
    print "field2=$fields[0]\n";
    print "field3=$fields[0]\n";
    }

close(INPUT);

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

I get the following when I run it

---------------------------------------------------------------------------------------------------------------------
perl qwe.pl
==641.59 $' 19|641.59 B|TX725.H1
B49|-|1364|1|DEAN|1|TOWN|COOK|0|0|19971126|641.59 B|==
field0=
field1=
field2=
field3=

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

Any ideas?



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

Date: 28 Jul 2006 18:44:52 GMT
From: xhoster@gmail.com
Subject: Re: Text::ParseWords::parse_line bug?
Message-Id: <20060728145156.359$Bz@newsreader.com>

"tsotsi" <alexbasa@gmail.com> wrote:
> Does anyone know of any bug in ParseWords?  I have an input string that
> I want to split on the pipe using ParseWords since split removes
> trailing pipes with empty data.

Split only does that if you don't supply a nonzero 3rd argument.  So supply
a negative 3rd argument.

Text::ParseWords doesn't split at delimiters that are inside quotes.
In your case, all the delimiters are inside (techincal, after an
unbalanced) quote.

Xho

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


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

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


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