[25687] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7928 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 31 06:05:37 2005

Date: Thu, 31 Mar 2005 03:05:10 -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, 31 Mar 2005     Volume: 10 Number: 7928

Today's topics:
        Can't get new listener after I stop my script <someone@microsoft.com>
    Re: Can't get new listener after I stop my script <1usa@llenroc.ude.invalid>
    Re: Can't get new listener after I stop my script <tadmc@augustmail.com>
    Re: FAQ 4.41 How can I remove duplicate elements from a <sams@freeddns.org>
    Re: FAQ 4.41 How can I remove duplicate elements from a <postmaster@castleamber.com>
        Getting Perl to ignore Letters when calculating numbers <bass150db@gmail.com>
    Re: Getting Perl to ignore Letters when calculating num <postmaster@castleamber.com>
    Re: Getting Perl to ignore Letters when calculating num <tadmc@augustmail.com>
    Re: Getting Perl to ignore Letters when calculating num <bass150db@gmail.com>
    Re: Getting Perl to ignore Letters when calculating num <joe@inwap.com>
        Information transfer over the internet <dzluk8fsxsw0001@sneakemail.com>
    Re: Information transfer over the internet (Anno Siegel)
    Re: Information transfer over the internet <dzluk8fsxsw0001@sneakemail.com>
    Re: Information transfer over the internet (Anno Siegel)
    Re: launching a Perl script .... (David Efflandt)
    Re: problem with old version of (Active) Perl <tadmc@augustmail.com>
    Re: Question on perl script. (Anno Siegel)
        SQL Server Connection strings (Zeke Hoskin)
        Understanding - qx codefixer@gmail.com
    Re: Understanding - qx <postmaster@castleamber.com>
    Re: Understanding - qx <joe@inwap.com>
    Re: Using HTTPS with LWP::UserAgent = Bad Service <richard.lawrence@gmail.com>
    Re: Using HTTPS with LWP::UserAgent = Bad Service <richard.lawrence@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 30 Mar 2005 19:08:36 -0500
From: "not entered" <someone@microsoft.com>
Subject: Can't get new listener after I stop my script
Message-Id: <_bH2e.14196$w63.911534@news20.bellglobal.com>

I've got a perl script running on a linux box.  The script uses a socket
server and when I stop the script and restart it, I can't get a listener for
about 5 minutes.  The line that I'm using to get the listener is:

$manager = new IO::Socket::INET ( Listen => 5, LocalPort => 1099);

SOMETIMES I can get a new listener right away...  most of the time it takes
about 5 minutes... occasionally it takes 10 or 20 mins.

Does anyone know what's happening?  Should I be stopping the script more
gracefully?

Stephen. 




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

Date: Thu, 31 Mar 2005 00:32:30 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Can't get new listener after I stop my script
Message-Id: <Xns9629C6CC2F14asu1cornelledu@127.0.0.1>

"not entered" <someone@microsoft.com> wrote in
news:_bH2e.14196$w63.911534@news20.bellglobal.com: 

> I've got a perl script running on a linux box.  The script uses a
> socket server and when I stop the script and restart it, I can't get a
> listener for about 5 minutes.  The line that I'm using to get the
> listener is: 
> 
> $manager = new IO::Socket::INET ( Listen => 5, LocalPort => 1099);
> 
> SOMETIMES I can get a new listener right away...  most of the time it
> takes about 5 minutes... occasionally it takes 10 or 20 mins.
> 
> Does anyone know what's happening?  Should I be stopping the script
> more gracefully?

http://unlser1.unl.csi.cuny.edu/faqs/sock-faq/html/unix-socket-faq-
4.html

See

ReuseAddr   Set SO_REUSEADDR before binding

in 

<URL: http://search.cpan.org/~nwclark/perl-
5.8.6/ext/IO/lib/IO/Socket/INET.pm>

Sinan


-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Wed, 30 Mar 2005 20:16:19 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Can't get new listener after I stop my script
Message-Id: <slrnd4mnbj.b3t.tadmc@magna.augustmail.com>

not entered <someone@microsoft.com> wrote:
             ^^^^^^^^^^^^^^^^^^^^^

[snip]


Please consider using a non-defaulted posting address.

There have been plenty of idiots posting with that address, 
you don't want to be associated with them I would guess.

More people will see your posts if you choose some other address.


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


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

Date: 30 Mar 2005 23:23:16 -0800
From: "Ohm" <sams@freeddns.org>
Subject: Re: FAQ 4.41 How can I remove duplicate elements from a list or array?
Message-Id: <1112253796.405277.326210@o13g2000cwo.googlegroups.com>

Hi I have done few Perl scripting once and now out of touch. Appreciate
if any help here to understand this:

I have a sorted text file each line has name. But someentries got
duplicated. I want to remove the dulplicates using Perl.

This is my dup.txt file
Aaron
Aaron
Andy
Beth
Lisa
Sam
Sam
Simon
Tim
Zewie

This is what I have done sofar to find a resolution based on the FAQ.
But I need more help to get it working.

open (INPUT,  "dup.txt")|| die "No dup.txt file\n" ;    # Open dup.txt
file
open (OUTPUT, ">clean.txt"); # Open a Clean file for output.

  chomp( my @in = <INPUT>);
  $prev = "not equal to $in[0]";
  @OUTPUT = grep($_ ne $prev && ($prev = $_, 1), @in);


foreach my $line (@OUTPUT) {
  chomp;
  print OUTPUT "$line \n";
}
close (INPUT);       #close INPUT  file
close (OUTPUT);      #close OUTPUT file



Appreciate any help

Sam.


PerlFAQ Server wrote:
> This message is one of several periodic postings to
comp.lang.perl.misc
> intended to make it easier for perl programmers to find answers to
> common questions. The core of this message represents an excerpt
> from the documentation provided with Perl.
>
> --------------------------------------------------------------------
>
> 4.41: How can I remove duplicate elements from a list or array?
>
>     There are several possible ways, depending on whether the array
is
>     ordered and whether you wish to preserve the ordering.
>
>     a)  If @in is sorted, and you want @out to be sorted: (this
assumes all
>         true values in the array)
>
>             $prev = "not equal to $in[0]";
>             @out = grep($_ ne $prev && ($prev = $_, 1), @in);
>
>         This is nice in that it doesn't use much extra memory,
simulating
>         uniq(1)'s behavior of removing only adjacent duplicates. The
", 1"
>         guarantees that the expression is true (so that grep picks it
up)
>         even if the $_ is 0, "", or undef.
>
>     b)  If you don't know whether @in is sorted:
>
>             undef %saw;
>             @out = grep(!$saw{$_}++, @in);
>
>     c)  Like (b), but @in contains only small integers:
>
>             @out = grep(!$saw[$_]++, @in);
>
>     d)  A way to do (b) without any loops or greps:
>
>             undef %saw;
>             @saw{@in} = ();
>             @out = sort keys %saw;  # remove sort if undesired
>
>     e)  Like (d), but @in contains only small positive integers:
>
>             undef @ary;
>             @ary[@in] = @in;
>             @out = grep {defined} @ary;
>
>     But perhaps you should have been using a hash all along, eh?
>
>
>
> --------------------------------------------------------------------
>
> Documents such as this have been called "Answers to Frequently
> Asked Questions" or FAQ for short.  They represent an important
> part of the Usenet tradition.  They serve to reduce the volume of
> redundant traffic on a news group by providing quality answers to
> questions that keep coming up.
>
> If you are some how irritated by seeing these postings you are free
> to ignore them or add the sender to your killfile.  If you find
> errors or other problems with these postings please send corrections
> or comments to the posting email address or to the maintainers as
> directed in the perlfaq manual page.
>
> Note that the FAQ text posted by this server may have been modified
> from that distributed in the stable Perl release.  It may have been
> edited to reflect the additions, changes and corrections provided
> by respondents, reviewers, and critics to previous postings of
> these FAQ. Complete text of these FAQ are available on request.
>
> The perlfaq manual page contains the following copyright notice.
>
>   AUTHOR AND COPYRIGHT
>
>     Copyright (c) 1997-2002 Tom Christiansen and Nathan
>     Torkington, and other contributors as noted. All rights
>     reserved.
>
> This posting is provided in the hope that it will be useful but
> does not represent a commitment or contract of any kind on the part
> of the contributers, authors or their agents.



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

Date: 31 Mar 2005 07:28:00 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: FAQ 4.41 How can I remove duplicate elements from a list or array?
Message-Id: <Xns962AEEB4EF3castleamber@130.133.1.4>

Ohm wrote:

> Hi I have done few Perl scripting once and now out of touch. Appreciate
> if any help here to understand this:
> 
> I have a sorted text file each line has name. But someentries got
> duplicated. I want to remove the dulplicates using Perl.

read a line
check if it's in the hash, if it is, next
store it in the hash
write it out

Don't top post, the FAQ doesn't like that.

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


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

Date: 30 Mar 2005 20:54:13 -0800
From: "bass150db" <bass150db@gmail.com>
Subject: Getting Perl to ignore Letters when calculating numbers.
Message-Id: <1112244853.333850.249710@l41g2000cwc.googlegroups.com>

Hello All,

    I need assistance with Perl Math.  I have a script running to
calculate percentages based on an array of numbers.  The script works
great.  However, I am using this as a foreach on mulitple arrays.  Some
of these arrays have letters where numbers should be.  How can I get
PERL to ignore the arrays with letters and process the arrays with
numbers only?  Any assistance is greatly appreciated.
Here is an excerpt of my script.  Thank you.

foreach $stock (@stock) {
	@numbers = <MYFILE2>;
	$low = (sort { $a <=> $b } @numbers)[0];
	$high = (sort { $a <=> $b } @numbers)[-1];
	$diff = (($high - $low) / $low) * 100;
	$diffround = sprintf("%.2f",$diff);



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

Date: 31 Mar 2005 05:55:08 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Getting Perl to ignore Letters when calculating numbers.
Message-Id: <Xns9629F3505517Fcastleamber@130.133.1.4>

bass150db wrote:

> Hello All,
> 
>     I need assistance with Perl Math.  I have a script running to
> calculate percentages based on an array of numbers.  The script works
> great.  However, I am using this as a foreach on mulitple arrays.  Some
> of these arrays have letters where numbers should be.

Then don't put them there :-D

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


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

Date: Thu, 31 Mar 2005 00:18:05 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Getting Perl to ignore Letters when calculating numbers.
Message-Id: <slrnd4n5gt.bjo.tadmc@magna.augustmail.com>

bass150db <bass150db@gmail.com> wrote:

> I am using this as a foreach on mulitple arrays.


> foreach $stock (@stock) {
> 	@numbers = <MYFILE2>;
> 	$low = (sort { $a <=> $b } @numbers)[0];
> 	$high = (sort { $a <=> $b } @numbers)[-1];


Why are you doing the expensive sort operation twice
on the same list?

   my($low, $high) = (sort { $a <=> $b } @numbers)[0,-1];


> 	$diff = (($high - $low) / $low) * 100;
> 	$diffround = sprintf("%.2f",$diff);


Your code does not use a foreach on mulitple (sic) arrays!

There is only one array in your code.

So, what was the problem again?


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


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

Date: 30 Mar 2005 22:41:14 -0800
From: "bass150db" <bass150db@gmail.com>
Subject: Re: Getting Perl to ignore Letters when calculating numbers.
Message-Id: <1112251273.956201.314200@o13g2000cwo.googlegroups.com>

Thanks for the one line code for sort, Tad.   Consolidating code
doesn't come easy for me.  The trouble is I have a CSV file.  The third
column should contain numbers.  Some of the CSV's have test in them
instead.  When I run my script, it dies the first time it sees letters
instead of numbers.

Let assume I have two arrays as follows:

1.  @number = qw( 10 20 300);
2.  @letters = qw(A B C);

I want to run a FOREACH command to look at all arrays and total only
the ones with numbers.  How can I get PERL to ignore Arrays with
letters and continue down the list?


open (STOCKFILE, "p:/Input/allstocks_difference.txt");
@stock = <STOCKFILE>;
chomp (@stock);

foreach $stock (@stock) {
	open (MYFILE, "p:/data/daily 5 minute/$stock.csv");
	@array = <MYFILE>;
	open (OUTFILE, ">p:/temp/difference/$stock.txt");
	foreach $line (@array) {
	@split = split (/,/,$line);
	print OUTFILE "@split[2]\n";
}
}
close (MYFILE);
close (OUTFILE);

open (LOGFILE, ">p:/Logs/Difference.csv");
print "Content-type: text/html\n\n";
foreach $stock (@stock) {
	open(MYFILE2, "p:/temp/difference/$stock.txt");
	@numbers = <MYFILE2>;
	$low = (sort { $a <=> $b } @numbers)[0];
	$high = (sort { $a <=> $b } @numbers)[-1];
	$diff = (($high - $low) / $low) * 100;
	$diffround = sprintf("%.2f",$diff);
	print "<BR>The difference between high and low for <A
HREF=\"http://finance.yahoo.com/q?s=$stock&d=t\">$stock</A> is
$diffround%\n";
	print LOGFILE "$stock, $diffround%\n";
	print LOFGILE "\n";
}

P.S.  I know this code is jacked.  I create a file, save it, then
reference it again later to produce output all in the same script.
Like I mentioned early, I can't consolidate.  I am still learning.  Any
assistance again is appreciated.  Thank you for the help.



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

Date: Thu, 31 Mar 2005 01:04:19 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: Getting Perl to ignore Letters when calculating numbers.
Message-Id: <7tednU1a5aCLINbfRVn-jQ@comcast.com>

bass150db wrote:

> I want to run a FOREACH command to look at all arrays and total only
> the ones with numbers.  How can I get PERL to ignore Arrays with
> letters and continue down the list?

Simple.  Just ask perl to go to the _next_ entry whenever
non-digits are matched.

1) Learn how the 'next' operator works when looping through arrays.
2) Learn the basics of regular-expression pattern matching,
    which includes character classes for digits and non-digits.

The statement you want is something like
	next if blahblahblah;
What to use for blahblahblah is an exercise for the OP.

		-Joe

P.S. The above talks about skipping an entry in an array
      that contains numbers and letters.  Skipping an entire
      array when letters are detected is also simple, as long
      as you're using an array of array references.


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

Date: Thu, 31 Mar 2005 09:46:41 +0200
From: "Jonas Nilsson" <dzluk8fsxsw0001@sneakemail.com>
Subject: Information transfer over the internet
Message-Id: <d2g9r9$n70$1@news.island.liu.se>

Hello
I would like to transfer some information between two computers with
internet connection. One computer should act as a server and the other as a
client. I really don't know much about sockets, ports or protocols.

I played around some with the code below but i reallt don't know what I am
doing. The module Net::Server::NonBlocking2 is the same as
Net::Server::NonBlocking, but I removed some error checking due to problems
with unimplemented perl funcions on my PC. This actually givs some
information to a browser when I type http://127.0.0.1:10000. This however
isn't working properly.I actually have to close the client to get any
response at all. There must be some modules that easily and nicely can do
something like the quasicode below.

Please assist me.
/jN

_CODE_
use Net::Server::NonBlocking2;
$|=1;

$obj=Net::Server::NonBlocking2->new({"pidfile" => "tmppid.pid"});
$obj->add({
 server_name => 'tic tac toe',
 local_port => 10000,
 timeout => 60,
 delimiter => "\n",
 on_connected => \&ttt_connected,
 on_disconnected => \&ttt_disconnected,
 on_recv_msg => \&ttt_message,
});
our $cnt="000";
$obj->start;
sub ttt_connected {
 my $self=shift;
 my $client=shift;
 print "connect:\t$client\n";
}
sub ttt_disconnected {
 my $self=shift;
 my $client=shift;
 print "disconnect:\t$client\n";
}
sub ttt_message {
 my $self=shift;
 my $client=shift;
 my $message=shift;
 print "(mess ",$cnt++,")\n";
 print "$message\n";
 print $client "dfgdg: message<BR>testmessage<BR>";
 $client->close;
}

_QUASICODE_

server:
while (1) {
    if (&new_message) {
        my $input=&message;
        my $output=&parse($input);
        &send_message($output);
    } else {
        sleep(5);
    }
}

client:
my $request="Give me checksum of C:/Tmp/test.txt";
my $answer=&send_request($request,"mycomp.mynet.com") or "Die no answer!";
&handle($answer);




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

Date: 31 Mar 2005 08:37:51 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Information transfer over the internet
Message-Id: <d2gcsv$iul$1@mamenchi.zrz.TU-Berlin.DE>

Jonas Nilsson <dzluk8fsxsw0001@sneakemail.com> wrote in comp.lang.perl.misc:
> Hello
> I would like to transfer some information between two computers with
> internet connection. One computer should act as a server and the other as a
> client. I really don't know much about sockets, ports or protocols.

A Perl newsgroup is not the first choice of a place to learn about them.

> I played around some with the code below but i reallt don't know what I am
> doing. The module Net::Server::NonBlocking2 is the same as
> Net::Server::NonBlocking, but I removed some error checking due to problems
> with unimplemented perl funcions on my PC.

Then the module (which I don't know) is probably not fit to run in
your environment.  In a situation where you are not entirely sure
what you are doing, dropping error checks is a bad idea.

>                                            This actually givs some
> information to a browser when I type http://127.0.0.1:10000.

So you want to write a web server.  This is hard to do from scratch,
as you are trying to do.  You should use a module that supports the
HTTP protocol.  There is a group of modules HTTP::Server::... on
CPAN that look promising.

Anno


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

Date: Thu, 31 Mar 2005 10:59:07 +0200
From: "Jonas Nilsson" <dzluk8fsxsw0001@sneakemail.com>
Subject: Re: Information transfer over the internet
Message-Id: <d2ge38$qeo$1@news.island.liu.se>

> Jonas Nilsson <dzluk8fsxsw0001@sneakemail.com> wrote in
comp.lang.perl.misc:
> >                                            This actually givs some
> > information to a browser when I type http://127.0.0.1:10000.


"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:d2gcsv$iul$1@mamenchi.zrz.TU-Berlin.DE...
> So you want to write a web server.

Actually no. I just try to do some learning by playing around... Not very
successfuly however, since the issue is a bit more complex than I realized.

Actually I need something very simple that can send strings/binaries over
the internet between a perl-client and a perl-server. Re-posting the
quasicode from the initial message might clear up my intentions:

_QUASICODE_

server:
while (1) {
    if (&new_message) {
        my $input=&message;
        my $output=&parse($input);
        &send_message($output);
    } else {
        sleep(5);
    }
}

client:
my $request="Give me checksum of C:/Tmp/test.txt";
my $answer=&send_request($request,"mycomp.mynet.com") or "Die no answer!";
&handle($answer);





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

Date: 31 Mar 2005 09:35:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Information transfer over the internet
Message-Id: <d2gg9o$llm$1@mamenchi.zrz.TU-Berlin.DE>

[newsgroup comp.lang.perl.modules trimmed, this is off topic there]

Jonas Nilsson <dzluk8fsxsw0001@sneakemail.com> wrote in comp.lang.perl.misc:
> > Jonas Nilsson <dzluk8fsxsw0001@sneakemail.com> wrote in
> comp.lang.perl.misc:
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:d2gcsv$iul$1@mamenchi.zrz.TU-Berlin.DE...

> > >                                            This actually givs some
> > > information to a browser when I type http://127.0.0.1:10000.
> 
> > So you want to write a web server.
> 
> Actually no. I just try to do some learning by playing around... Not very
> successfuly however, since the issue is a bit more complex than I realized.

If you are using a browser for a client, it expects a web server for
a server, so that's what you will have to write.  The "universal client"
under Unix is telnet, not a browser.

> Actually I need something very simple that can send strings/binaries over
> the internet between a perl-client and a perl-server. Re-posting the
> quasicode from the initial message might clear up my intentions:
> 
> _QUASICODE_

You mean "pseudocode".

> server:
> while (1) {
>     if (&new_message) {

Don't use "&" on subroutine calls, unless you know what you are doing.

>         my $input=&message;
>         my $output=&parse($input);
>         &send_message($output);
>     } else {
>         sleep(5);
>     }
> }
> 
> client:
> my $request="Give me checksum of C:/Tmp/test.txt";
> my $answer=&send_request($request,"mycomp.mynet.com") or "Die no answer!";
> &handle($answer);

What you have there isn't pseudocode, it's incomplete Perl code.  The
definitions of the subroutines are missing.  What you are basically
asking is for us to supply the six(!) subs so that your code does what
we are supposed to guess it should do.  That's a tall order, so I
snipped it in my first reply.

If you just want to play with a server/client model in Perl, I recommend
the module Net::EasyTCP.  You can pick a client/server pair directly from
the examples and modify them as desired.

Anno


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

Date: Thu, 31 Mar 2005 00:18:17 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: launching a Perl script ....
Message-Id: <slrnd4mge8.bjt.efflandt@typhoon.xnet.com>

On 29 Mar 2005 19:06:13 -0800, joesplink <wdflannery@aol.com> wrote:
> I can launch a Perl script when a user clicks a submit button on a
> form...... and I can launch a Perl script when a user clicks on a
> link..... but..... can I launch Perl script A from Perl script B ????
> 
> The reason it seems like a good idea is that script B puts up a
> form.... and the form potentially needs to be brought up at various
> points in a session, and I'd like to do it in one place.....

You really should post CGI questions in a CGI newsgroup.

But what I usually do is use a single script to generate the initial form
on $ENV{REQUEST_METHOD} eq "GET", and process or go to the next form if
not (doesn't matter if POST or post or Post), with previous data as hidden
fields.  I determine what to do next based on the name of the submit
button.


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

Date: Wed, 30 Mar 2005 16:03:49 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: problem with old version of (Active) Perl
Message-Id: <slrnd4m8i5.a6g.tadmc@magna.augustmail.com>

Joe Smith <joe@inwap.com> wrote:
> Fabian Pilkowski wrote:
>> just your escaped backslashes in filenames give less readability
>> than a simple forward slash »/« which is already sufficient on windows.
> 
> You should qualify that statement.  Forward slashes can be used
> instead of backslashes in Perl programs.  The same is not true
> for other Windows programs invoked by exec(), system(), or qx``.


Is that true even for 

   system PROGRAM LIST

where there is no shell involved?


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


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

Date: 31 Mar 2005 09:17:15 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Question on perl script.
Message-Id: <d2gf6r$kun$1@mamenchi.zrz.TU-Berlin.DE>

Unix_Shell <sgtembe@hotmail.com> wrote in comp.lang.perl.misc:
> Hello Group,
> 
> I am very new to the perl language and don't know much about it. I had
> a question & maybe someone can help me decipher/modify a script.
> 
> We have AIX 5.2 & the script (test.sh) contains the following perl
> command:
> 
> /usr/bin/perl
> -014pe's|^|"'$PAGE1FORM'".(/Page:\s+1\s/?"\n":"'$CONTFORMSFX'\n")|e'

That's a single perl command line, presumably embedded in a shell
script.  Since you don't show the rest of the script, it's hard to
guess what is going on.

> Basically, two values are being passed to this script. Variable
> PAGE1FORM will contain $1 (example: "m_inv01") and CONTFORMSFX will
> contain $2 (example: "_09").
> 
> Basically, the script is invoked as follows:
> 
> ./test.sh m_inv01 _09 < inrptfile > outrptfile
> 
> The perl command processes the inrptfile by substituting the first line
> of page 1 with m_inv01 and substituting the first line from page 2
> onwards with m_inv01_09 (concatenation of $1 & $2).

It does nothing of this sort.  It doesn't substitute lines, it inserts
a new line in front of each form-feed-delimited record.  If the record
contains the string "Page: 1 ", it inserts the concatenation of the
input variables, otherwise it only inserts the second variable.

> Question: How can I make it substitute something completely different
> from page 2 onwards? So, if I run the script as follows:

It should do that, provided appropriate input.  Apparently your input
data doesn't conform to what the script assumes.

If you change the Perl code to

    s|^|"'$PAGE1FORM'".($.==1?"\n":"'$CONTFORMSFX'\n")|e

it will base the notion of "first page" on the record count in $.

But most of all you should rewrite the script as a Perl script.  Perl
command lines are for the command line.  Perl scripts are best written
as Perl scripts, not shell scripts.

Anno


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

Date: 30 Mar 2005 17:59:41 -0800
From: zeke@zekehoskin.com (Zeke Hoskin)
Subject: SQL Server Connection strings
Message-Id: <773b5af7.0503301759.1f627ac3@posting.google.com>

I need to write a Perl program to append records to a SQL Server db. I
can connect to it using a connection string lifted from an Access
project:

my $dbh = DBI->connect("DBI:ADO:Provider=Microsoft.Access.OLEDB.10.0;
Persist Security Info=False;Data Source=##NAMEOFSERVER##;
Integrated Security=SSPI;Initial Catalog=##NAMEOFDB##;Data
Provider=SQLOLEDB.1")
     or die "connection failed: $DBI::errstr\n";
This (surprisingly) works if I just query the database, but if I send
it a correct INSERT statement, it carries it out and then crashes with
no DBI errmsg and a screen that says "Microsoft has to shut down the
Perl database interface". (An incorrect insert just dies properly with
a message.)

If I edit the Provider= phrase, it very nicely refuses to connect and
dies with a long and informative message. Obviously there is a correct
Provider phrase, but I can't find it. Suggestions?
Thanks//Zeke Hoskin


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

Date: 30 Mar 2005 22:45:56 -0800
From: codefixer@gmail.com
Subject: Understanding - qx
Message-Id: <1112251556.120205.9620@z14g2000cwz.googlegroups.com>

Hi,

I have the following line in my script test.pl running on Red Hat
Linux.

my $result = qx/g++ -Wno-deprecated test.cpp/;

If test.cpp fails to compile, then all the errors messages are shown on
screen.

The same script when run on Windows and replacing the compiler by "cl"
nothing spits on screen and everything is returned in $result.

Any idea for the occurance of this discrepancy ?

Thanks.



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

Date: 31 Mar 2005 07:17:51 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Understanding - qx
Message-Id: <Xns962AD3348BBBcastleamber@130.133.1.4>

 wrote:

> Hi,
> 
> I have the following line in my script test.pl running on Red Hat
> Linux.
> 
> my $result = qx/g++ -Wno-deprecated test.cpp/;
> 
> If test.cpp fails to compile, then all the errors messages are shown on
> screen.
> 
> The same script when run on Windows and replacing the compiler by "cl"
> nothing spits on screen and everything is returned in $result.
> 
> Any idea for the occurance of this discrepancy ?

cl outputs to stdout I guess, and g++ to stderr. Redirect stderr to stdout 
when you use g++.

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


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

Date: Thu, 31 Mar 2005 01:11:43 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: Understanding - qx
Message-Id: <XeSdnUdOM8NII9bfRVn-rw@comcast.com>

codefixer@gmail.com wrote:

> I have the following line in my script test.pl running on Red Hat
> Linux.
> 
> Windows: nothing spits on screen and everything is returned in $result.
> 
> Any idea for the occurance of this discrepancy ?

There's an FAQ on this subject, the key word is "STDERR".
	perldoc -q STDERR
Pay attention to all the examples using `2>`.

		-Joe


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

Date: 31 Mar 2005 00:43:18 -0800
From: "Richard  Lawrence" <richard.lawrence@gmail.com>
Subject: Re: Using HTTPS with LWP::UserAgent = Bad Service
Message-Id: <1112258597.978207.9770@f14g2000cwb.googlegroups.com>

Ilmari Karonen wrote:
> > HTTPS_PROXY=http://10.10.200.44:8080/
> > HTTPS_PROXY_USERNAME=richard
> > HTTPS_PROXY_PASSWORD=mypassword
>
> This, however, seems to work just fine.  Of course, I can't really
> test if the authentication works or not, but at least there is no
> error.  You're reporting that you get the same "Bad service" error
> each time, but I'd really suggest you try it one more time, and make
> sure $ENV{HTTPS_PROXY} really contains what you think it does.  You
> could add something like this to your code to dump the relevant
> environment variables:
>
>   /^HTTPS?_PROXY/ and print "$_=$ENV{$_}\n" for sort keys %ENV;

Hi there,

Thanks for your advise. I've made the changes you recommended and get
the following output:

$ perl testproxy.pl 1
HTTPS_PROXY=http://10.10.200.44:8080/
HTTPS_PROXY_PASSWORD=mypassword
HTTPS_PROXY_USERNAME=richard
HTTP_PROXY=http://10.10.199.45:80/
Going to get https://www.nodeworks.com
Using HTTPS proxy http://10.10.200.44:8080/
Result is:
500 (Internal Server Error) Can't connect to www.nodeworks.com:443 (Bad
service '8080/')
Content-Type: text/plain
Client-Date: Thu, 31 Mar 2005 08:35:51 GMT
Client-Warning: Internal response

500 Can't connect to www.nodeworks.com:443 (Bad service '8080/')

Interestingly enough, using "wget" and "lynx" both give me a timeout
error so I'm wondering if it is actually something to do with my
environment settings.

In that case, I think I need to find another newsgroup!

Regards,

Richard.



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

Date: 31 Mar 2005 00:57:34 -0800
From: "Richard  Lawrence" <richard.lawrence@gmail.com>
Subject: Re: Using HTTPS with LWP::UserAgent = Bad Service
Message-Id: <1112259454.081562.148530@o13g2000cwo.googlegroups.com>

Richard  Lawrence wrote:
> $ perl testproxy.pl 1
> HTTPS_PROXY=http://10.10.200.44:8080/
> HTTPS_PROXY_PASSWORD=mypassword
> HTTPS_PROXY_USERNAME=richard
> HTTP_PROXY=http://10.10.199.45:80/
> Going to get https://www.nodeworks.com
> Using HTTPS proxy http://10.10.200.44:8080/
> Result is:
> 500 (Internal Server Error) Can't connect to www.nodeworks.com:443
(Bad
> service '8080/')
> Content-Type: text/plain
> Client-Date: Thu, 31 Mar 2005 08:35:51 GMT
> Client-Warning: Internal response
>
> 500 Can't connect to www.nodeworks.com:443 (Bad service '8080/')
>
> Interestingly enough, using "wget" and "lynx" both give me a timeout
> error so I'm wondering if it is actually something to do with my
> environment settings.

As an update, I've set up a cascading proxy on my computer which runs
locally and then redirects everything through the main proxy with the
correct username and password.

Setting HTTP_PROXY and HTTPS_PROXY to http://127.0.0.1:8080/ with no
username and password (plus their lowercase versions for the benefit of
lynx which doesn't see the upper-case ones) works just fine.

However, my perl code still reports "500 (Internal Server Error) Can't
connect to www.nodeworks.com:443 (Bad service '8080/')" which brings me
back around full circle to thinking that my implementation is wrong.

If you have any suggestions, it would be appreciated!

Thanks,

Richard.



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

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


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