[29196] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 440 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 16 14:10:12 2007

Date: Wed, 16 May 2007 11:09:04 -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           Wed, 16 May 2007     Volume: 11 Number: 440

Today's topics:
    Re: looking for perl professionals <dha@panix.com>
    Re: Net::FTP and firewalls - patched in CPAN.pm <drawson1.take.this.out@earthlink.dot.net>
    Re: Parsing a text file line-by-line: skipping badly-fo (Greg Bacon)
    Re: Parsing a text file line-by-line: skipping badly-fo (Greg Bacon)
        Simple Regular Expression Help vunet.us@gmail.com
        Store Object Class in DBM Hash michael.shnitzer@gmail.com
    Re: use warnings and -w behaviour <simon.andrews@bbsrc.ac.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 16 May 2007 17:35:56 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: looking for perl professionals
Message-Id: <slrnf4mg7t.j9g.dha@panix2.panix.com>

On 2007-05-14, Doug <roaring.chicken@gmail.com> wrote:
> Hello ,
>
> My name is Doug Cohen and I am a Senior Recruiter 

You have posted a job posting or a resume in a technical group.

Longstanding Usenet tradition dictates that such postings go into
groups with names that contain "jobs", like "misc.jobs.offered", not
technical discussion groups like the ones to which you posted.

Had you read and understood the Usenet user manual posted frequently to
"news.announce.newusers", you might have already known this. :)  (If
n.a.n is quieter than it should be, the relevent FAQs are available at
http://www.faqs.org/faqs/by-newsgroup/news/news.announce.newusers.html)
Another good source of information on how Usenet functions is
news.newusers.questions (information from which is also available at
http://www.geocities.com/nnqweb/).

Please do not explain your posting by saying "but I saw other job
postings here".  Just because one person jumps off a bridge, doesn't
mean everyone does.  Those postings are also in error, and I've
probably already notified them as well.

If you have questions about this policy, take it up with the news
administrators in the newsgroup news.admin.misc.

http://jobs.perl.org may be of more use to you

Yours for a better usenet,

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
John Cleese was my favorite. Next was Tom Baker.
	- http://www.jerkcity.com/jerkcity2412.html


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

Date: Mon, 14 May 2007 11:40:59 -0400
From: Dan Rawson <drawson1.take.this.out@earthlink.dot.net>
Subject: Re: Net::FTP and firewalls - patched in CPAN.pm
Message-Id: <46488026$0$9311$88260bb3@news.teranews.com>

Sherm Pendley wrote:
> Dan Rawson <drawson1.take.this.out@earthlink.dot.net> writes:
> 
>> :-)) That would be my first choice . . . . it's an authentication problem of
>> some type.
>>
>> ncftp is set to use what they call a "type 7" firewall, which looks like
>> this in the ncftp config file:
>>
>> #    type 7:  Connect to firewall host, but send
>> #             "USER user@real.host.name fwuser" and
>> #             "PASS pass" followed by
>> #             "ACCT fwpass" to complete the login.
>>
>> ftp_passive is on in the ncftp config file.  However, setting FTP_PASSIVE in
>> the environment doesn't change the behavior.
>>
>> I can set the proxy host and port, but I can't figure any way (from
>> the Net::FTP documentation) to set the required user name and password
>> for the firewall.
> 
> Does this recipe work for you?
> 
>     <http://perldoc.perl.org/Net/libnetFAQ.html#I-am-behind-an-FTP-proxy-firewall%2c-but-cannot-access-machines-outside-%3f>
> 
> If it does, then I'd imagine that CPAN.pm could be patched to use it.
> 
> sherm--
> 
Sherm -

Well, it wasn't the answer, but the FAQ DID get me going the right direction 
 . . . . modifying CPAN.pm like this (inside the ftp_get sub  . . .):


     #
     # DBR - following four lines modified to connect through Blue Coat Proxy
     # $ftp = Net::FTP->new($host);
     my $ftp = Net::FTP->new('proxyhost');
     $ftp->login("anonymous@".$host." remote_pass proxy_user");
     $ftp->quot('ACCT', "proxy_pass");
     unless ($ftp->site($host)) {
         $CPAN::Frontend->mywarn("  Could not connect to host '$host' with 
Net::FTP\n");
         return;
     }

This appears to be specific to our "Blue Coat FTP Service" proxy . . . .

Maybe someone else will find this useful . . .:-)

Thanks!

Dan


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

Date: Wed, 16 May 2007 14:49:15 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Parsing a text file line-by-line: skipping badly-formed lines?
Message-Id: <134m6fbioieebe7@corp.supernews.com>

In article <n36l4314vo5rm77cbaiu69p81ni1vb7p97@4ax.com>,
    Bart Lateur  <bart.lateur@pandora.be> wrote:

: Check to see if that last line contains a chr(26). If that's the case
: and you're on Windows, use binmode on the handle. Text mode treats a
: chr(26) (AKA ctrl-Z, "\cZ")  as an end of line marker, while binary mode
: does not.

Denis said Linux is the operating system.

Greg
-- 
I have always found it remarkable that so many men and women are prepared to
distrust any and all businessmen -- whose appeals, in a free market, they are
free to ignore -- while trusting even the most corrupt or cruel politician --
whose demands they fail to meet at their peril.   -- Butler Shaffer


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

Date: Wed, 16 May 2007 15:06:39 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Parsing a text file line-by-line: skipping badly-formed lines?
Message-Id: <134m7fv48a4e933@corp.supernews.com>

In article <1179259750.483378.83000@o5g2000hsb.googlegroups.com>,
     <denis.papathanasiou@gmail.com> wrote:

: So the way I solved the problem was to use a different file read
: strategy: instead of using a line-by-line loader like <>, I load n
: bytes at a time into a vector.
:
: Since the file is fixed-width, I can treat the vector conceptually as
: a 2d array and pull out any "line" I need.

But what about the records that aren't properly terminated? Won't
that throw off your count?

: Also, I can wrap the byte reads inside a condition-handler, so that
: when I see the i/o error ("when", not "if" because the file *is*
: corrupted), I can log the error lines, yet keep going all the way to
: the end.

Are you able to actually continue reading after the I/O error?

: I wound up coding this in CL, not perl, though, because I couldn't
: find any references to file reads in perl that did not involve the <>
: construct, and also because the CL condition/exception handling logic
: seems more robust than perl's.

There are alternatives:

    perldoc -f read
    perldoc -f sysread

: If there's a way to do the same thing -- i.e., read byte blocks into a
: vector, allowing for the possibility of an i/o error without stopping
: -- in perl (and I'm sure there is), I'd be interested in learning how.

You might try something along the following lines:

    #! /usr/bin/perl

    use strict;
    use warnings;

    use Fcntl qw/ SEEK_SET /;

    my $RECORDSZ = 20;

    my $IN_FILE = $0;

    open IN, "<:raw", $IN_FILE or die "$0: open: $!";

    my $nrec = 0;
    while (sysseek IN, $nrec * $RECORDSZ, SEEK_SET) {
      my $nread = sysread IN, my($buf), $RECORDSZ;

      if (defined $nread) {
        if ($nread == 0) {
          exit 0; # eof
        }
        else {
          $buf =~ s{([^[:graph:] ])} {
            "<" . sprintf("%02X", ord $1) . ">"
          }ge;

          print "$nrec: $buf\n";
        }
      }
      else {
        warn "$0: $IN_FILE:$nrec: sysread: $!";
      }

      ++$nrec;
    }

    die "$0: sysseek: $!";

When run (against itself, which you'll need to change), it gives

    0: #! /usr/bin/perl<0A><0A>us
    1: e strict;<0A>use warnin
    2: gs;<0A><0A>use Fcntl qw/ S
    3: EEK_SET /;<0A><0A>my $RECO
    4: RDSZ = 20;<0A><0A>my $IN_F
    5: ILE = $0;<0A><0A>open IN, 
    6: "<:raw", $IN_FILE or
    7:  die "$0: open: $!";
    8: <0A><0A>my $nrec = 0;<0A>whil
    9: e (sysseek IN, $nrec
    10:  * $RECORDSZ, SEEK_S
    11: ET) {<0A>  my $nread = 
    12: sysread IN, my($buf)
    13: , $RECORDSZ;<0A><0A>  if (
    14: defined $nread) {<0A>  
    15:   if ($nread == 0) {
    16: <0A>      exit 0; # eof
    17: <0A>    }<0A>    else {<0A>  
    18:     $buf =~ s{([^[:g
    19: raph:] ])} {<0A>       
    20:  "<" . sprintf("%02X
    21: ", ord $1) . ">"<0A>   
    22:    }ge;<0A><0A>      print
    23:  "$nrec: $buf\n";<0A>  
    24:   }<0A>  }<0A>  else {<0A>   
    25:  warn "$0: $IN_FILE:
    26: $nrec: sysread: $!";
    27: <0A>  }<0A><0A>  ++$nrec;<0A>}<0A><0A>
    28: die "$0: sysseek: $!
    29: ";<0A>

I'm interested in knowing whether this approach allows processing
to continue after the I/O error.

Keep in mind that you're hitting a lower-level failure than malformed
data: the filesystem is failing to provide data.

Hope this helps,
Greg
-- 
When buying and selling are controlled by legislation, the first
things to be bought and sold are legislators.
    -- P. J. O'Rourke


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

Date: 16 May 2007 10:51:01 -0700
From: vunet.us@gmail.com
Subject: Simple Regular Expression Help
Message-Id: <1179337861.793364.184800@e65g2000hsc.googlegroups.com>

How can I strip this line with regular expession to get 12345 number
within brackets:

$line = "some text is here (12345 ms)";

This did not work:

$text = $line;
$text =~ m/\((\d+)\)/;



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

Date: 16 May 2007 09:41:44 -0700
From: michael.shnitzer@gmail.com
Subject: Store Object Class in DBM Hash
Message-Id: <1179333704.186470.138700@h2g2000hsg.googlegroups.com>

It was my understanding that once a DBM hash was tied to a file, it
can be accessed using the same methods as a regular hash.  For
simplicities sake I created a small perl program to demonstrate what I
am trying to do:

***********************************
#! /usr/bin/perl -w
use warnings;

my %hash = ( );
dbmopen(%hash, ".data/documents", 0777);
$hash{mike} = new Document;

print $hash{mike}->docno;

package Document;

sub new
{
  my $self = {
    document_number => "DOC123",
  };
  bless $self;
}

sub docno
{
  my $self = shift;
  return $self->{document_number};
}
**************************************

If I run this program with the DBM hash it returns "Can't locate
object method "docno" via package "Document=HASH(0x4001d0cc)" (perhaps
you forgot to load "Document=HASH(0x4001d0cc)"?) at read.pl line 11."

But if I run this program without opening the DBM hash, then the
program returns the expected result of DOC123.

Obviously there is a difference in accessing the hash data when it is
being read from a DBM hash that I am missing.

Any suggestions would be appreciated.

Thanks,

--Mike



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

Date: Wed, 16 May 2007 14:57:03 +0100
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Re: use warnings and -w behaviour
Message-Id: <f2f2jd$lo3$1@south.jnrs.ja.net>

Jorge wrote:
>>>> When I use the -w in the shebang line ...
>>>> #!/usr/local/bin/perl -w
>>>> the scripts run just fine but when I switch to the 'use warnings'
>>>> pragma ...
>>>> I get the error ...
>>>> Command not found
> 
> Yup -- it was the 2-byte newlines that were causing the problem.
> 
> dos2unix fixed it.

Another useful tip is to use

#!/usr/local/bin/perl --
use warnings;
etc..

The -- stops the shell from reading any further and will work on a 
system using any kind of line ending.

Simon.


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

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 V11 Issue 440
**************************************


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