[19664] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1859 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 3 00:05:34 2001

Date: Tue, 2 Oct 2001 21:05:07 -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: <1002081907-v10-i1859@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 2 Oct 2001     Volume: 10 Number: 1859

Today's topics:
    Re: $count = (@emails); <ilya@martynov.org>
    Re: 2 newlines after Headerlines in HTTP? (David Efflandt)
    Re: binmode with "perl -p" doesn't work (Joe Smith)
    Re: Bug or Error in Perl Compiler? (Joe Smith)
        filehandles between functions <citykid@nospam.edu>
    Re: filehandles between functions (Mark Jason Dominus)
    Re: filehandles between functions (Garry Williams)
    Re: filehandles between functions <uri@sysarch.com>
    Re: IO::Socket && IO::Select Problem <goldbb2@earthlink.net>
    Re: Perl via metasend <bart.lateur@skynet.be>
        Please advise on directions <mberloga@sympatico.ca>
    Re: Please advise on directions <nobody@nowhere.com>
    Re: Please advise on directions <mbudash@sonic.net>
    Re: Reduce "cell" where should I start (newbie) <bart.lateur@skynet.be>
    Re: Regexp question <wyzelli@yahoo.com>
        search and replacement (Tim)
    Re: search and replacement <ronh@iainc.com>
        Socket closes early on local machine (Long Pham)
    Re: Socket closes early on local machine <goldbb2@earthlink.net>
    Re: Sourcing Things in Perl ? (Joe Smith)
    Re: Urgently need help with Net::SSH::Perl / Math::Pari <toby@tobyperkins.org>
    Re: XS Question <adverts@teaselsyn.co.uk>
    Re: Yet another fork question <goldbb2@earthlink.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 03 Oct 2001 01:28:42 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: $count = (@emails);
Message-Id: <87snd1ived.fsf@abra.ru>

>>>>> On Tue, 02 Oct 2001 15:35:58 +0000, Todd Anderson <todd@mrnoitall.com> said:

TA> I need the code below to count the number of addresses associated with
TA> $username. This code works in other areas of the script. Why doesn't it
TA> work here? All your help is appreciated.

You should show us format of you file. It is always hard to guess why
someone's code doesn't work without known what data is should operate
on. Anyway some lines look too suspicious.

TA> open (FILE, "$ejdy") || &file_open_error
TA> ("$ejdy", "Group Email",  __FILE__, __LINE__);

TA>  while (<FILE>)
TA>     {
TA>     $line = $_;
TA>     chop $line;

Just a note. IMHO it is better to use chomp instead of chop because
last line can be without \n. And as additional bonus it is more
portable (Win32 system have two chars as line separator).

TA>     @fields = split (/\|/, $line);

TA> if($fields[1] eq "$username") {
TA> @emails = ("$fields[0]");

This assigns to @email an array with one element equal to value of
first element of @fields. If @fields doesn't have any elements it will
assign to @email an array with one element equal to empty string.

TA> $count = (@emails);##<<<< code in question here<<<<<<<

This will always return 1 because @email always contains exactly one
element.

TA> @emails = sort {lc($a) cmp lc($b)} @emails;
TA>       foreach $email (@emails){
TA> $email_group .= qq~<option value="$email">$email~;
TA> }
TA> }

TA> }#while

TA> close (FILE);

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: Wed, 3 Oct 2001 01:54:19 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: 2 newlines after Headerlines in HTTP?
Message-Id: <slrn9rkrub.1o5.efflandt@typhoon.xnet.com>

On Tue, 02 Oct 2001, Rainer Klier <Rainer.Klier@erl.sbs.de> wrote:
> Hi,
> 
> to make visible, what a browser sends to a webserver,
> I coded this tiny webserver, that shall bounce the
> Requestheader back to the Browser.
> Interesstingly it says, that the browser sent
> 2 newlines after the headerrequest. RFC 2616 says,
> there should be one newline. Did I miss something?

Hint, if you have a newline after EACH header line and then a blank line
terminated with a newline, what is between the newline for the last header
line and the newline for the blank line?  Nothing.  Therefore, tha last
header line effectively ends with 2 newlines.

-- 
David Efflandt - All spam is ignored - http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Wed, 3 Oct 2001 01:48:19 +0000 (UTC)
From: inwap@best.com (Joe Smith)
Subject: Re: binmode with "perl -p" doesn't work
Message-Id: <9pdqp3$1dhn$1@nntp1.ba.best.com>

In article <a73bcad1.0110012300.53397c24@posting.google.com>,
John Lin <johnlin@chttl.com.tw> wrote:
>So, do you think my proposal of "perl -b" switch for binmode is considerable?
>What can I contribute to make it happen?

Go to the perl5-porters mailing list archive and read a couple weeks worth
of messages to see how patches and program enhancements are handled.

http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2001-09/threads.html

Fetch a copy of the current development sources, using something like
  rsync -avz rsync://ftp.linux.activestate.com/perl-current/ src/perl-5.7.x/
and read Porting/patching.pod and the various README files.

Modify the sources to get "-b" working the way you want it.
Create a binmode.t file to test the new functionality.
Create a unified 'diff' comparing the original files versus your mods.
Submit the diff to the perl5-porters list and hope it is accepted.
	-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: Wed, 3 Oct 2001 01:03:39 +0000 (UTC)
From: inwap@best.com (Joe Smith)
Subject: Re: Bug or Error in Perl Compiler?
Message-Id: <9pdo5b$1ddh$1@nntp1.ba.best.com>

In article <3bb85486.14183887@news.screaming.net>,
Mark <mark@artwarren.co.ukNOSPAM> wrote:
>Bug or Error in Perl Compiler?
>
>Can't find string terminator "HTML CONTENTS" anywhere before EOF at
>filename.pl line xxx.

It usually means there there are non-printing characters after "CONTENTS"
in your file.  Such as a trailing blank, or a CR+LF instead of LF only.
The latter occurs when a file is transfered from Win32 to Unix using
FTP in BINARY instead of TEXT mode.  Try deleting the HTML CONTENTS line
and retyping it, making sure that there are no leading or trailing blanks.
	-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: Tue, 2 Oct 2001 16:01:34 -0700
From: Les Ander <citykid@nospam.edu>
Subject: filehandles between functions
Message-Id: <Pine.LNX.4.33.0110021549350.18913-100000@schewanella.stanford.edu>

Hi,
Usually what i do when i want to read a file is

sub read_file
{
  open(IN,$infile) or die "...";
  while(my $line=<IN>)[
     chomp $line;
     $full_file.=$line;
  }
  close(IN).
  return $full_file;
}

However, i have an extremely huge file (~20 M) and I don't
have much RAM. So I would like to use do the following but i don't
know how to do it:
I would like to write a routine called get_one_line(), which
gets the next line. However, i am not sure how i can acheive this
as i need to know where i am in the file.

my $file_pos=0;
sub some_routine
{
   my $fileHandle=new FileHandle("<$infile");
   while(my $line=&get_next_line($fileHandle)){
       process($line);
   }
  close ($fileHandle);
}

sub get_next_line
{
   return_the_line_after_the_file_pos;
 ...
}
I guess what I am asking is : How do i pass around a file handle.
I saw an example in perldoc -q "filehandle" but i am still not
clear on this.
any help on this is much appreciated.
les



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

Date: Wed, 03 Oct 2001 02:12:13 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: filehandles between functions
Message-Id: <3bba73fc.6eb9$10f@news.op.net>

In article <Pine.LNX.4.33.0110021549350.18913-100000@schewanella.stanford.edu>,
Les Ander  <citykid@nospam.edu> wrote:
>my $file_pos=0;
>sub some_routine
>{
>   my $fileHandle=new FileHandle("<$infile");
>   while(my $line=&get_next_line($fileHandle)){
>       process($line);
>   }
>  close ($fileHandle);
>}
>
>sub get_next_line
>{
>   return_the_line_after_the_file_pos;
>...
>}
>I guess what I am asking is : How do i pass around a file handle.

You passed it (in some_routine) exactly correctly.  To receive it in
get_next_line, just do:

        sub get_next_line {
          my $fh = shift;               

To read a line from the handle, use

          my $line = <$fh>;
          return $line;
        }

You don't need to keep track of the current position in the file; the
filehandle does that automatically.   (That's what a filehandle is for.)

But it's not really clear why you need get_next_line at all:

        sub some_routine
        {
           my $fileHandle=new FileHandle("<$infile");
           while(my $line= <$fileHandle> ){
               process($line);
           }
           close ($fileHandle);
        }

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Wed, 03 Oct 2001 03:31:56 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: filehandles between functions
Message-Id: <slrn9rl1l6.cm0.garry@zfw.zvolve.net>

On Tue, 2 Oct 2001 16:01:34 -0700, Les Ander <citykid@nospam.edu> wrote:
> Usually what i do when i want to read a file is
> 
> sub read_file
> {
>   open(IN,$infile) or die "...";
>   while(my $line=<IN>)[
                        ^-- typo
>      chomp $line;
>      $full_file.=$line;
>   }
>   close(IN).
>   return $full_file;
> }

I wonder why you *usually* read a file this way?  If you must do such
a thing, then this would be more reasonable: 

  sub read_file {
    open( my $fh, $infile ) || die "can't open '$infile': $!\n";
    chomp( my @lines = <$fh> );
    return join "", @lines;
  }

(The file is closed automatically as soon as $fh goes out of scope.)  

> However, i have an extremely huge file (~20 M) and I don't
> have much RAM. 

A good reason to change your "usual" behavior.  :-)  

> So I would like to use do the following but i don't
> know how to do it:
> I would like to write a routine called get_one_line(), which
> gets the next line. However, i am not sure how i can acheive this
> as i need to know where i am in the file.

  sub get_one_line { scalar <$fh> }

But why would you do this instead of just using the <> operator
in-line?  

[snip]

> I guess what I am asking is : How do i pass around a file handle.
> I saw an example in perldoc -q "filehandle" but i am still not
> clear on this.
> any help on this is much appreciated.

I admit that the entries printed by perldoc -q filehandle can be a bit
confusing to some.  Here's two ways to pass around a file handle: 

1.  The easiest.  If you have perl 5.6.x, just open a file using an
uninitialized lexical (my) variable as above: 

  open( my $fh, "< in_file" ) || die "can't open 'in_file': $!\n";

Now you can pass around $fh, if you must.  

2.  For older versions of Perl, use the IO::File module (or for really
older Perl versions, use the FileHandle module): 

  use IO::File;
  my $fh = IO::File->new( "< in_file" )
    || die "can't open 'in_file': $!\n";

or

  use FileHandle;
  my $fh = FileHandle->new( "< in_file" )
    || die "can't open 'in_file': $!\n";

-- 
Garry Williams


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

Date: Wed, 03 Oct 2001 03:59:23 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: filehandles between functions
Message-Id: <x74rph9xvo.fsf@home.sysarch.com>

>>>>> "GW" == Garry Williams <garry@ifr.zvolve.net> writes:

  GW>   sub read_file {
  GW>     open( my $fh, $infile ) || die "can't open '$infile': $!\n";
  GW>     chomp( my @lines = <$fh> );
  GW>     return join "", @lines;
  GW>   }

if you want to slurp a file, this is a useful sub

sub read_file {

	my( $file_name ) = shift ;

	my( $buf ) ;

	local( *FH ) ;

	open( FH, $file_name ) || carp "can't open $file_name $!" ;

	return <FH> if wantarray ;

	read( FH, $buf, -s FH ) ;
	return $buf ;

# older slow way
#	local( $/ ) unless wantarray ;
#	<FH>
}

that is much faster and works in scalar and list contexts.

now, don't go starting that slurping is bad and line by line is good
thread again. :)

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs  --------------------------  http://jobs.perl.org


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

Date: Tue, 02 Oct 2001 18:45:52 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: IO::Socket && IO::Select Problem
Message-Id: <3BBA43A0.6E5274D0@earthlink.net>

NuArb wrote:
> 
> "Benjamin Goldberg" <goldbb2@earthlink.net> schrieb im Newsbeitrag
> news:3BB6AE5E.AA1B7EC9@earthlink.net...
> 
> Hi !
> 
> Thanks for the time you spend to help me !
> 
> ...
> > > The same result is when I startet the VB MDI on two NT boxes with
> > > each have 50 instances.
> > >
> > > And when try more than 127 connections + 1 listen my perlserver
> > > crashes.
> >
> > That *sounds* like you've got a system limit on the number of open
> > connections.  What kind of error does perl output to the console
> > when it crashes?
> 
> None ! I call the script with "perl -Tw chat.pl" and the result on the
> console is the
> following:
> 
> IP [fileno]: Message [IO::Select->Count()]
> 
> ...
> 10.84.39.163[127]: Connected [124]
> 10.84.39.163[128]: Connected [125]
> E:\Perl>
> 
> Thats it ! No errormessage !

Ahh... Ok, do this:  In your original script, after the loop that starts
out "while(@ready = $select->can_read) {" finishes, add a line which
says "print STDERR "can_read returned empty list: $!";"

> The problem is not the amount of open connections. The problem is
> IO::Select. It can not handle more than 128.
> 
> If I try to the code without IO::Select than I can accept 128+.
> 
> > Might I suggest that you run a number of servers on your machine to
> > spread the load?
> 
> And what kind of communication would you prefer between the servers ?

Not sure.  Thought will be required.

[snip]
> I had to change some things in your code to get it run (under Windows
> 2000) BUT without "use strict" because I get
> the in the Typeglob assignment line the error msg "Variable "$buffer"
> is not imported at chat3.pl line 56.".

The way to fix that is to add, just before the local assignment to
*buffer, a line saying "our $buffer;"

[snip]
>         #my $client = $clients{$socket}; #client is empty !

I find *this* to the strangest thing in your post... it shouldn't be
empty, and I can't think why it would be.

-- 
"I think not," said Descartes, and promptly disappeared.


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

Date: Tue, 02 Oct 2001 21:14:01 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Perl via metasend
Message-Id: <vebkrtgl9cb6nvcbbq0q9kivdf1ae7060r@4ax.com>

Donnajeanne Liu wrote:

[snip]

>How do I send 1 email, using metasend, with 2 files attached?

Gee. I think it would be easiest to drop all this, and just use
Mime::Lite both to construct the mail with attachments, and send it.

-- 
	Bart.


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

Date: Tue, 2 Oct 2001 18:34:01 -0400
From: "Michael Greenberg" <mberloga@sympatico.ca>
Subject: Please advise on directions
Message-Id: <L8ru7.9323$Ve4.1455298@news20.bellglobal.com>

Good day!
I'm writing application in Perl. One of the things it does is it retrieves
index.html from a certain website reads it, gets news headlines and saves
them formatted as multidimensional array in news.js file, so that The
JavaScript would use it for dynamic headline updates. My question is where
should I look and what should I read to make the proggy go and retrieve this
page every 1 hour. lets say. Sockets, TCP/IP or this is not where I should
look?

Thanks in advance

Mike




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

Date: Wed, 3 Oct 2001 09:52:28 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: Re: Please advise on directions
Message-Id: <Wosu7.39948$812.50123@newsfeeds.bigpond.com>

"Michael Greenberg" <mberloga@sympatico.ca> wrote in message
news:L8ru7.9323$Ve4.1455298@news20.bellglobal.com...
 My question is where
> should I look and what should I read to make the proggy go and retrieve
this
> page every 1 hour.
Cron?

gtoomey




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

Date: Tue, 02 Oct 2001 23:56:16 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Please advise on directions
Message-Id: <mbudash-0F6134.16562002102001@news.sonic.net>

In article <L8ru7.9323$Ve4.1455298@news20.bellglobal.com>, "Michael 
Greenberg" <mberloga@sympatico.ca> wrote:

> Good day!
> I'm writing application in Perl. One of the things it does is it 
> retrieves
> index.html from a certain website reads it, gets news headlines and saves
> them formatted as multidimensional array in news.js file, so that The
> JavaScript would use it for dynamic headline updates. My question is 
> where
> should I look and what should I read to make the proggy go and retrieve 
> this
> page every 1 hour. lets say. Sockets, TCP/IP or this is not where I 
> should
> look?
> 

if i understand your question, it seems that you already have the hard 
part done. if you're on a *nix system, i.e., one with a cron daemon 
running, just set the crontab to have the script called every hour, and 
have the script create a new news.js file it the proper dir each time. 
i'd call the new file 'news.js.new', then rename it to 'news.js'. that 
way, any process asking for 'news.js' will be much less likely to get a 
half-built version.
 
hth-
-- 
Michael Budash ~~~~~~~~~~ mbudash@sonic.net


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

Date: Tue, 02 Oct 2001 21:35:32 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Reduce "cell" where should I start (newbie)
Message-Id: <dnbkrto53uee6mruo5rhfjr4srj53umdnn@4ax.com>

Åke Wahlberg wrote:

>I did download the "Parse-RecDescent-1.80", and had a look ...
>have you used this yourself ??, do have any example how to use it ??

Damian Conway, perler extraordinaire and author of this module, also has
written a tutorial for this module, under the title "the man(1) of
descent", which first appeared in the magazine "The Perl Journal" AKA
"TPJ". It is also on CPAN:

<http://search.cpan.org/doc/DCONWAY/Parse-RecDescent-1.80/tutorial/tutorial.html>


And I agree, the syntax you're trying to analyze looks like a "good old"
grammar to me.

-- 
	Bart.


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

Date: Wed, 3 Oct 2001 09:50:35 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Regexp question
Message-Id: <tJsu7.8$TI5.409@wa.nnrp.telstra.net>

<slidge@slidge.com> wrote in message
news:E0qu7.19429$ck.127345@sjc-read.news.verio.net...
>   I am writing a Perl script to parse DNS zone files, and I'm coming up
>   against my limitations concerning my knowledge of regexp.  Bear with me,
>   I'm not a Perl wiz.
>
>   What I am trying to do is "Append the contents of the variable $origin
>   to the variable $line if $line does not end with the character "." and
>   if line does not end with an IP address (like 10.0.0.1), and if the
>   value of the variable $type is not "HINFO", "TXT", or "UNKNOWN".
>
>   The snippet I have is:
>
>   $line = $line.".".$origin
>     if (( $line =~ /^.*[^\.]$/
>   && $line =~ /[^\d+\.\d+\.\d+\.\d+]$/ )

That regex is definitely not what you are trying to do.  The [ and ] create
a character class within which you have repeated \d, + \. all negated.

>     && ( $type ne "HINFO"
>           && $type ne "TXT"
>   && $type ne "UNKNOWN"));
>

This looks like a classic case for the 'unless' as per below:

unless ($type eq 'HINFO' || $type eq 'TXT' || $type eq 'UNKNOWN'){
    unless ($line =~ /\.$/ || $line =~ /(\d+\.){3}\d+$/){
        $line .= $origin;
    }
}

Explained as:

unless ($type eq 'HINFO' || $type eq 'TXT' || $type eq 'UNKNOWN'){

# If $type matches we don't proceed

    unless ($line =~ /\.$/ || $line =~ /(\d+\.){3}\d+$/){

# If there is a trailing . or IP number (dot quad format) in $line, we don't
proceed
        $line .= $origin;

#append $origin to $line


    }
}



I think the logic is easier to follow, because it tests all the conditions
first, with no 'negative logic'.

Wyzelli
--
@x='074117115116032097110111116104101114032080101114108032104097099107101114
'=~/(...)/g;
print chr for @x;







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

Date: 2 Oct 2001 17:30:30 -0700
From: tvn007@hotmail.com (Tim)
Subject: search and replacement
Message-Id: <21724be2.0110021630.6715c09a@posting.google.com>

hi,
Could someone please help me on this ?

Here is an example of input file:



 sp_X  abc xxx same red123 132xe2
 sp_S  001 LLL same orange 123dxe 
 sp_J  011 001 same 123456 ddd1ee
 sp_S  xyx HHH same xxxxxx abcdef

Here is what I would like to have on the output:

Just replace LLL with xxx in column 3
Just replace HHH with xxx in column 3
          
sp_X  abc xxx same red123 132xe2
sp_S  001 xxx same orange 123dxe 
sp_F  011 001 same 123456 ddd1ee
sp_W  xyx xxx same xxxxxx abcdef




My perl script does not do the trick !!

$input_file =  "test.file";
$output_file =  "TEMP_OUTPUT";





	$edge_set = "sp_X|sp_F|sp_W|sp_S";

open (OUTFILE,">$output_file") || die "ERROR: cannot open output file
for writing\n";

		

open (LVM,$input_file) || die "ERROR: cannot open input file for
reading\n";

	while (<LVM>){

		chomp $_;
		print "$_\n";

		if (/$edge_set/){
			substr($_,10,3)='xxx';
			}
			
		print OUTFILE "$_\n";

			
		}


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

Date: Wed, 03 Oct 2001 01:08:33 GMT
From: "Ron Hartikka" <ronh@iainc.com>
Subject: Re: search and replacement
Message-Id: <lytu7.7275$Gd6.142230@typhoon.mw.mediaone.net>

Maybe this is not what you want:

open('IN', '<C:\RON\PERL\examples\in.txt') or die $!;
open('OUT', '>C:\RON\PERL\examples\out1.txt') or die $!;
select OUT;

while (<IN>){
 s/LLL/xxx/;
 s/HHH/xxx/;
 print ;

}

__END__

in.txt
sp_X  abc xxx same red123 132xe2
sp_S  001 LLL same orange 123dxe
sp_J  011 001 same 123456 ddd1ee
sp_S  xyx HHH same xxxxxx abcdef

out1.txt
sp_X  abc xxx same red123 132xe2
sp_S  001 xxx same orange 123dxe
sp_J  011 001 same 123456 ddd1ee
sp_S  xyx xxx same xxxxxx abcdef

"Tim" <tvn007@hotmail.com> wrote in message
news:21724be2.0110021630.6715c09a@posting.google.com...
> hi,
> Could someone please help me on this ?
>
> Here is an example of input file:
>
>
>
>  sp_X  abc xxx same red123 132xe2
>  sp_S  001 LLL same orange 123dxe
>  sp_J  011 001 same 123456 ddd1ee
>  sp_S  xyx HHH same xxxxxx abcdef
>
> Here is what I would like to have on the output:
>
> Just replace LLL with xxx in column 3
> Just replace HHH with xxx in column 3
>
> sp_X  abc xxx same red123 132xe2
> sp_S  001 xxx same orange 123dxe
> sp_F  011 001 same 123456 ddd1ee
> sp_W  xyx xxx same xxxxxx abcdef
>
>
>
>
> My perl script does not do the trick !!
>
> $input_file =  "test.file";
> $output_file =  "TEMP_OUTPUT";
>
>
>
>
>
> $edge_set = "sp_X|sp_F|sp_W|sp_S";
>
> open (OUTFILE,">$output_file") || die "ERROR: cannot open output file
> for writing\n";
>
>
>
> open (LVM,$input_file) || die "ERROR: cannot open input file for
> reading\n";
>
> while (<LVM>){
>
> chomp $_;
> print "$_\n";
>
> if (/$edge_set/){
> substr($_,10,3)='xxx';
> }
>
> print OUTFILE "$_\n";
>
>
> }




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

Date: 2 Oct 2001 15:44:54 -0700
From: lrmpham@hotmail.com (Long Pham)
Subject: Socket closes early on local machine
Message-Id: <7c70e7a2.0110021444.50621368@posting.google.com>

I have the following script that basically opens a connection on a
port - 2349 - sends a request to the listening process then listens
and receives the resulting buffers from that process.  The problem
that I'm experiencing is:

If the script and the other process resides on different machines on
the network, everything works and the script can receive the entire
buffer from the process.  However, if the script and the other process
resides on the same machine, the script can only receive part of the
buffer from the sending process, and the port closes.

This is on a NT 4.0 platform.  Has anyone else experiece this problem
?  Any advice or suggestions is greatly appreciated.  Thanks.


$port = 2349;
$passed = $ARGV[0];
$AF_INET = 2;
$SOCK_STREAM = 1;
$sockaddr = 'S n a4 x8';
$them='208.193.119.100';

$server_protocol = $ENV{'SERVER_PROTOCOL'};
$server_software = $ENV{'SERVER_SOFTWARE'};

($name,$aliases,$proto) = getprotobyname('tcp');
($name, $aliases, $type, $len, $thataddr) = gethostbyname($them);

$this = pack($sockaddr, $AF_INET, 0, $thisaddr);
$that = pack($sockaddr, $AF_INET, $port, $thataddr);
if (socket(S, $AF_INET, $SOCK_STREAM, $proto)) {
#   print "socket ok\n";
}
else {
   die $!;
}
if (bind(S, $this)) {
#   print "bind ok\n";
}
else {
   die $!;
}
if (connect(S,$that)) {
#   print "connect ok\n";
}
else {
   die $!;
}
$current_handle = select(S);
$| = 1;
select($current_handle);
 print S $passed,"\n";

print "HTTP/1.0 200 OK\nServer: $server_software\nContent-type:
text/html\n\n";

#  print S $query_string;
while (<S>) {
   print;
}
close (S);
exit (0);


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

Date: Wed, 03 Oct 2001 00:01:41 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Socket closes early on local machine
Message-Id: <3BBA8DA5.1E5E5C20@earthlink.net>

Long Pham wrote:
> 
> I have the following script that basically opens a connection on a
> port - 2349 - sends a request to the listening process then listens
> and receives the resulting buffers from that process.  The problem
> that I'm experiencing is:
> 
> If the script and the other process resides on different machines on
> the network, everything works and the script can receive the entire
> buffer from the process.  However, if the script and the other process
> resides on the same machine, the script can only receive part of the
> buffer from the sending process, and the port closes.
> 
> This is on a NT 4.0 platform.  Has anyone else experiece this problem
> ?  Any advice or suggestions is greatly appreciated.  Thanks.

While I don't know why you are having your particular problem, I *can*
suggest a solution.

Get rid of all of your Socket.pm code, and replace it with IO::Socket
code.  That will make it much easier to read and maintain.

Also, it looks like this is meant as a CGI script, so you should
probably be using CGI.pm

#!/usr/local/bin/perl -w
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(-nph);
use IO::Socket;
use strict;

print header( {Server => $ENV{SERVER_SOFTWARE}} );

my $socket = IO::Socket::INET->new(
   PeerAddr => "208.193.119.100", PeerPort => 2349,
) or die "Couldn't connect: $!";

select((select($socket),$|=1)[0]);

print $socket $ARGV[0], "\n";

$! = 0;
while( sysread( $socket, $_, 1024 ) ) {
   print;
}
die "Error reading socket: $!" if $!;

close $socket or die "Error closing socket: $!";

exit 0;
__END__

Isn't this code all much clearer?  Ok, so the select() part is a bit
less clear, but what I have is a standard perlish idiom which does what
your select code did, but without needing an extra variable.

-- 
"I think not," said Descartes, and promptly disappeared.


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

Date: Wed, 3 Oct 2001 01:28:30 +0000 (UTC)
From: inwap@best.com (Joe Smith)
Subject: Re: Sourcing Things in Perl ?
Message-Id: <9pdpju$1dgg$1@nntp1.ba.best.com>

In article <87u1xop3kh.fsf@limey.hpcc.uh.edu>,
Tony Curtis  <tony_curtis32@yahoo.com> wrote:
>>> On 27 Sep 2001 22:43:07 GMT,
>>> abigail@foad.org (Abigail) said:
>
>> Use one system command, not two.
>>     system "source $sourceme; modelsim";
>> That will start *one* shell, which first uses source
>> (setting environment variables), then executes modelsim.
>
>system() invokes the Bourne shell (/bin/sh).
>
>Using "." instead of "source" would probably make more
>sense (bash is not masquerading as sh everywhere, nor is
>one's login shell involved).

	system("csh","-c","source $sourceme; modelsim");

That starts up one new process, running csh instead of sh, and
has that instance of the c-shell execute the two commands.
	-Joe

--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: Tue, 2 Oct 2001 22:23:22 -0400
From: Toby Perkins <toby@tobyperkins.org>
Subject: Re: Urgently need help with Net::SSH::Perl / Math::Pari / @INC and loadable objects
Message-Id: <3bba7572$0$12700@dingus.crosslink.net>

>> I do have Math::Pari installed

> It appears that your Math::Pari was not successfully installed, because
> you don't have the "loadable object" (eg. the dynamic library) that is
> built from the XS and the PARI library. This would be a file like Pari.so.
> 

Hi, 
        I am having a potentially related problem with Math::Pari and 
the Net::SSH and Net::SFTP modules using Perl 5.6.1 and a (mostly) vanilla
install of Red Hat 7.1.   

        Today, I attempted to install (via perl -MCPAN) the module
Net::SFTP, which is dependent on Net::SSH.  Cascading dependencies 
led to a long series of other installations, but the whole house of cards 
came tumbling down when Math::Pari ultimately flunked its own make 
tests.  

        The outdated Math::Pari README gives instructions for applying 
patches.  These instructions are not only old, but in many ways ambiguous. 
Manually, I downloaded Math::Pari and tried to implement the patches.  

        Most of the patches (as I applied them, using patch) failed, with 
multiple error messages, and then (not surprisingly) the "patched" version
failed to compile, with a fatal gcc error message saying that a C function
call does not match its prototype.  

        I hunted this error down inside pari--*not* the Math::Pari code, 
but the pari C code itself.  A simple typographical error caused the gcc
failure.  This error indicates to me that the Math::Pari contributors had
never attempted to compile the (current) pari code with these patch
instructions.

        I am now trying to recompile, but of course I do not feel sanguine
about the eventual outcome.

        Here's my question: is there any way to install Net::FTP without
satisfying a dependency on Math::Pari?  Some configuration option I may
have missed?  Or is there some other SFTP client for Perl that I can use? 
Or any workaround (TMTOWTDI) to manipulate sftp in perl without human
interaction?  

        Constraining possible solutions, I have no control over the site 
where the sftpd server is running, which uses passwords for authentication.

        Thanks in advance,

-- Toby Perkins



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

Date: Wed, 03 Oct 2001 00:52:31 GMT
From: pkent <adverts@teaselsyn.co.uk>
Subject: Re: XS Question
Message-Id: <adverts-0AEBAF.01514403102001@news.cableinet.co.uk>

In article <m3d746mwnx.fsf@mumonkan.sunstarsys.com>,
 Joe Schaefer <joe+usenet@sunstarsys.com> wrote:
<some helpful things>

thanks very much. I'm also looking at using SWIG, which might be better 
for my purposes (basically taking computationally intensive maths stuff 
out of perl and into C). 

ta
P

-- 
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply


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

Date: Tue, 02 Oct 2001 23:06:14 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Yet another fork question
Message-Id: <3BBA80A6.332296F0@earthlink.net>

Mr. Sunblade wrote:
> 
> Hi all,
> 
> Solaris 8, Perl 5.6.1
> 
> I'm trying to do something relatively simple (I think):  fork a series
> of ssh calls (using Net::SSH::Perl, not the system call).
> 
> When using 'wait' it works fine, but I end up executing at the same
> speed as a non-forked version.  When using 'reapChild', it's clearly
> faster, but I'm not getting control back at the command line.
> 
> What obvious tidbit of code am I missing?
[snip]
> sub doForkStuff{
>    for(1..3){
>       my $pid = fork();
>       if($pid == 0){
[snip]
>          exit;
>       }
>       else{
>          #wait; # works, but then I'm just executing sequentially
>          reapChild();
>       }
>    }
> }

The obvious fault is that you should be doing:
for( 1..3 ) {
  defined(my $pid = fork()) or die "fork: $!";
  if(!$pid) {
    ... do child stuff ...
  }
}
for( 1..3 ) {
  wait;
}

Note that the wait()ing is all done *after* you've forked all your
children.

-- 
"I think not," said Descartes, and promptly disappeared.


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

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.  

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


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