[32483] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3748 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 2 03:09:25 2012

Date: Thu, 2 Aug 2012 00:09:08 -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           Thu, 2 Aug 2012     Volume: 11 Number: 3748

Today's topics:
    Re: "is-numeric" check? <oneingray@gmail.com>
    Re: "is-numeric" check? (Seymour J.)
    Re: "is-numeric" check? <rvtol+usenet@xs4all.nl>
    Re: a regex for removing a password in a source listing <cal@example.invalid>
    Re: a regex for removing a password in a source listing <uri@stemsystems.com>
    Re: a regex for removing a password in a source listing <uri@stemsystems.com>
    Re: a regex for removing a password in a source listing <cal@example.invalid>
    Re: a regex for removing a password in a source listing <NoSpamPleaseButThisIsValid3@gmx.net>
    Re: a regex for removing a password in a source listing <uri@stemsystems.com>
    Re: a regex for removing a password in a source listing <cal@example.invalid>
        i18n for netnews <oneingray@gmail.com>
        Man, has this newsgroup shrunk.  Why?  Where gone to? (David Combs)
    Re: Man, has this newsgroup shrunk.  Why?  Where gone t (Tim McDaniel)
    Re: Man, has this newsgroup shrunk.  Why?  Where gone t <rweikusat@mssgmbh.com>
        Time Question <edgrsprj@ix.netcom.com>
    Re: Time Question <NoSpamPleaseButThisIsValid3@gmx.net>
    Re: Time Question <ben@morrow.me.uk>
        using a help file to populate ftp values <cal@example.invalid>
    Re: using a help file to populate ftp values <ben@morrow.me.uk>
    Re: using a help file to populate ftp values <jurgenex@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 01 Aug 2012 17:07:49 +0700
From: Ivan Shmakov <oneingray@gmail.com>
Subject: Re: "is-numeric" check?
Message-Id: <86ipd3rklm.fsf@gray.siamics.net>

>>>>> Ruud  <rvtol+usenet@xs4all.nl> writes:
>>>>> On 2012-07-30 12:06, Ivan Shmakov wrote:
>>>>> Ruud  <rvtol+usenet@xs4all.nl> writes:
>>>>> On 2012-07-29 10:16, Ivan Shmakov wrote:

 >>>> Is there a simple way to check if a value is numeric in Perl?

 >>> No.  Why do you think that you need it?

 >> My program receives a crucial piece of information via its command
 >> line, and I'd like it to fail with a clear error message should a
 >> non-number be passed, instead of silently (or with a warning)
 >> interpreting it as zero.

 > So you need to validate user input.

	Yes.

 > For that you need to use a parser.

	Indeed, and the one that Perl provides is fine, as long as it
	allows for explicit validation.  And thanks to
	looks_like_number, it does.

 > How do you define 'numeric'?

	I see no point in extending Perl's own numeric syntax for my
	application.  Neither do I see any reason in using a "stricter"
	syntax than the one supported by Perl at this moment.

 > Does 1_000_000 == 1000000?

	As per the above, no.  OTOH, 1e6 == 1000000.

[...]

-- 
FSF associate member #7257	http://sf-day.org/


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

Date: Tue, 31 Jul 2012 17:35:13 -0400
From: Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>
Subject: Re: "is-numeric" check?
Message-Id: <50184f91$5$fuzhry+tra$mr2ice@news.patriot.net>

In <861ujtu6yn.fsf@gray.siamics.net>, on 07/30/2012
   at 12:57 PM, Ivan Shmakov <oneingray@gmail.com> said:

>	(In particular, I'm planning to work on a "NNTP server"
>	implementation next year, and it's likely that it will reject
>	messages with non-ASCII headers outright.)

That's appropriate for now, but keep your eye on the
internationalization efforts at IETF. There is an RFC set for
internationalized e-mail, and news is the obvious next step; I would
assume that such an enhancement will include a new capability in the
registry described in RFC 3977, 3.3.4.  Initial IANA Register.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org



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

Date: Wed, 01 Aug 2012 23:18:47 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: "is-numeric" check?
Message-Id: <50199d37$0$6943$e4fe514c@news2.news.xs4all.nl>

On 2012-07-30 23:59, Ben Morrow wrote:
> Quoth "Dr.Ruud" <rvtol+usenet@xs4all.nl>:

>> perl -Mstrict -wle'
>>     #local $SIG{"__WARN__"}= sub { die @_ };
>>     my $x= "x" + 1;
>>     print $x;
>> '
>>
>> If you need it to die on warnings, uncomment that SIG line.
>
> A better alternative would be
>
>      use warnings FATAL => "numeric";

When would that be better?

The sub allows you to decorate this in anyway you want.
Clearly superior. ;)

-- 
Ruud




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

Date: Tue, 31 Jul 2012 22:12:27 -0600
From: Cal Dershowitz <cal@example.invalid>
Subject: Re: a regex for removing a password in a source listing
Message-Id: <3vadnTVlcMAxMYXNnZ2dnUVZ_oudnZ2d@supernews.com>

On 07/30/2012 03:46 PM, Wolf Behrenhoff wrote:
> Am 30.07.2012 23:26, schrieb Cal Dershowitz:

> ah, you open the file in rw mode.

Thx for your comment, Wolf, I didn't have any luck with it at all.  For 
the small thing I'm doing, I just to decided to read the file into an 
array, manipulate the array, and then write it to a file.
>
>> while (<$gh>) {
>
> This is while (defined($_ =<$gh>)), i.e. you now have a new value in $_
> corresponding to a line. This is a copy! So modifying $_ doesn't do
> anything to the file!

I think I solve that here:

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

my $source_file = "/home/dan/Desktop/source/marni1.pl";
my (@lines);
open( my $gh, '<', $source_file )
   or die("Can't open $source_file  for writing: $!");
chomp( @lines = <$gh> );
close $gh;
my $name = 'post1.pl';
open( my $fh, '>', $name )
   or die("Can't open $name  for writing: $!");
foreach (@lines) {

     if (/\$password|\$username/) {
         print "matched\n";
         s/'.*'/'redacted'/;
     }
     $_ .= "\n";
     print $fh $_;
}


>
>>       chomp;
>>
>>       # this is not working
>>       # this may look obvious, but it's not
>>       #   s/my \$password = '.*';/my \$password = 'redacted';/;
>>       #  s/my \$username = '.*';/my \$username = 'redacted';/;
>>
>>       if (/\$password/) {
>>           print "matched\n";
>>           $_ =~ s/'.*'/'redacted'/;
>
> Are you sure about this replacement? Replacing anyhing between the first
> ' of the line and the last ' of the line?

It works in the context I'm using i, but I'd feel better if the regex 
checked for and equals sign being between them.  (a little ambitious for me)

> What about perl's in-place edit? See perldoc perlrun!
>
> Just run
> perl -pi -e 's/password/redacted/g' /path/to/iypjx_2.html
>
> or maybe
> perl -pi -e "s/'password'/'redacted'/g" /path/to/iypjx_2.html
> if you only want to replace the password if it is between single quotes.
>
> (you can also run perl -pi.bak -e ... to get a backup file with .bak
> extension)
>
> - Wolf
>

Those again, are clever and a little bit beyond my game, but I wouldn't 
see how they wouldn't do bad things to this line, which is very typical 
in an ftp program:

$ftp->login($username, $password)       or die "Couldn't login\n";


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

Date: Wed, 01 Aug 2012 00:29:35 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: a regex for removing a password in a source listing
Message-Id: <87zk6fnsk0.fsf@stemsystems.com>

>>>>> "WB" == Wolf Behrenhoff <NoSpamPleaseButThisIsValid3@gmx.net> writes:

  >> while (<$gh>) {

  WB> This is while (defined($_ = <$gh>)), i.e. you now have a new value in $_
  WB> corresponding to a line. This is a copy! So modifying $_ doesn't do
  WB> anything to the file!

wow. the OP had a massively odd view of rw files.


  WB> What about perl's in-place edit? See perldoc perlrun!

  WB> Just run
  WB> perl -pi -e 's/password/redacted/g' /path/to/iypjx_2.html

  WB> or maybe
  WB> perl -pi -e "s/'password'/'redacted'/g" /path/to/iypjx_2.html
  WB> if you only want to replace the password if it is between single quotes.

since he is doing this in a script and not the command line, edit_file
or edit_file_lines from File::Slurp with do that easily

use File::Slurp qw( edit_file ) ;

	edit_file { s/'password'/'redacted'/g } '/path/to/iypjx_2.html' ;

done.

to the OP: next time stop with the nonsense, the quine, the logs, and
just say you want to edit a file in place. pretty simple concept but you
said everything BUT that.

uri


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

Date: Wed, 01 Aug 2012 00:30:57 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: a regex for removing a password in a source listing
Message-Id: <87vch3nshq.fsf@stemsystems.com>

>>>>> "CD" == Cal Dershowitz <cal@example.invalid> writes:

  CD> my $source_file = "/home/dan/Desktop/source/marni1.pl";
  CD> my (@lines);
  CD> open( my $gh, '<', $source_file )
  CD>   or die("Can't open $source_file  for writing: $!");
  CD> chomp( @lines = <$gh> );

why chomp all the lines just to add a newline back later???
  CD> close $gh;
  CD> my $name = 'post1.pl';
  CD> open( my $fh, '>', $name )
  CD>   or die("Can't open $name  for writing: $!");
  CD> foreach (@lines) {

  CD>     if (/\$password|\$username/) {
  CD>         print "matched\n";
  CD>         s/'.*'/'redacted'/;
  CD>     }
  CD>     $_ .= "\n";
  CD>     print $fh $_;
  CD> }

see my other post for clean one line solution. 

uri


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

Date: Wed, 01 Aug 2012 00:00:21 -0600
From: Cal Dershowitz <cal@example.invalid>
Subject: Re: a regex for removing a password in a source listing
Message-Id: <KvmdnSPCfOxoWIXNnZ2dnUVZ_gSdnZ2d@supernews.com>

On 07/30/2012 05:00 PM, Ben Morrow wrote:
>
> Quoth Cal Dershowitz<cal@example.invalid>:
>> On 07/29/2012 07:10 AM, Ben Morrow wrote:
>>
>>> I'll try once more. Please explain, *IN ENGLISH*, what you are trying to
>>> do and what is not working. Dumping a whole lot of logs and code is not
>>> an alternative to an explanation.
>>
>> $ cat quine2.pl
>
> You have omitted the part where you explain in English what you are
> trying to do. It may be possible to divine from your code, but that is
> not the same as an explanation. An explanation looks something like
>
>      I am trying to open a Perl source file and copy it to another file
>      with all the passwords removed.

That's one little tool in a chain I'm trying build.  To hear you say it 
helped me figure out what I had to do.  I'm not trying to be a jerk 
about not describing the subject as well as I can, but if I knew what I 
was talking about, then I wouldn't have to ask questions.
>> When I run this on these ftp upload files that have my password in it, I
>> get "matched" 3 times like I would suspect, but I get no effective
>> substitution.  Tried several things now.   As you see it, there's
>> nothing that writes the line to the file.  When I add my best guess, I
>> get very exotic output, which I would show but for the insistence that I
>> not do so.
>
> You could at least show us what your best guess was, since I believe the
> substitution is working perfectly. You are, I hope, aware that
> attempting to overwrite a file while you are reading it is likely to
> produce confusing results? The normal procedure is to write a new file
> (you can create a secure temporary file with File::Temp) and rename it
> over the top.
>
> This
>
>      #!/usr/bin/perl
>
>      use warnings;
>      use strict;
>
>      while (<DATA>) {
>          if (/\$password/) {
>              s/'.*'/'redacted'/;
>          }
>          print;
>      }
>
>      __DATA__
>      use warnings;
>      use strict;
>      use Net::FTP;
>
>      my $password = 'foo';
>
>      my $F = Net::FTP->new(...);
>
> works for me: that is, it prints the contents of the DATA section with
> the password assignment replaced.

I certainly appreciate that you take the time to entertain yourself with 
my computer problems, ben.  That part was solid, but somehow I seemed to 
get tripped up in the same material tonight.  (see below)
>
>> Hasn't anyone else used a a script to erase his passwords so that he can
>> share his source without torpedoing his security?
>
> It's not a common thing to want to do, because it's generally a bad idea
> to put passwords directly in the script file in the first place. The
> best thing to do, if you need a password, is to prompt for it (you can
> use Term::ReadKey to prompt without echoing); if you must keep it in a
> file, make it a separate config file so the script can be shared with
> others/checked into a VCS/whatever without revealing your passwords.
>
> Ben
>

$ perl safe_post4.pl
String found where operator expected at safe_post4.pl line 17, near 
"$word =~ m/'(\w+)'"
	(Missing operator before '(\w+)'?)
syntax error at safe_post4.pl line 17, near "$word =~ m/'(\w+)'"
Unmatched right curly bracket at safe_post4.pl line 21, at end of line
syntax error at safe_post4.pl line 21, near "}"
Execution of safe_post4.pl aborted due to compilation errors.
$ cat safe_post4.pl
#!/usr/bin/perl -w
use strict;
use 5.010;
use Net::FTP;
my ($domain, $username, $password);
my $identity_file = 'ftp_passwords_1.txt';
my (@lines, $word);
open( my $gh, '<', $identity_file )
   or die("Can't open $identity_file  for writing: $!");
chomp(@lines = <$gh>);
close $gh;
print "@lines\n";

foreach (@lines) {
     if (/\$domain\) {
         print "matched\n";
         $word =~ m/'(\w+)'/;
         $domain = $word;
     }
print "domain is $domain\n";
}

$ cat ftp_passwords_1.txt
my $domain = 'www.bedrock.com';
my $username = 'barney';
my $password = 'rocks';
$

This looks like perl to me.  Perl.exe disagrees.  What gives?
-- 
Cal


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

Date: Wed, 01 Aug 2012 12:11:11 +0200
From: Wolf Behrenhoff <NoSpamPleaseButThisIsValid3@gmx.net>
Subject: Re: a regex for removing a password in a source listing
Message-Id: <501900c0$0$6578$9b4e6d93@newsspool3.arcor-online.net>

Am 01.08.2012 08:00, schrieb Cal Dershowitz:
>      if (/\$domain\) {
>          print "matched\n";
>          $word =~ m/

This is the whole match! From the first / right after the if to the
second one which only appears 2 lines later.

You simply forgot to end the match with / and used the \ instead.




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

Date: Thu, 02 Aug 2012 01:44:58 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: a regex for removing a password in a source listing
Message-Id: <87r4rponj9.fsf@stemsystems.com>

>>>>> "CD" == Cal Dershowitz <cal@example.invalid> writes:

  CD> On 07/31/2012 10:29 PM, Uri Guttman wrote:
  >> since he is doing this in a script and not the command line, edit_file
  >> or edit_file_lines from File::Slurp with do that easily
  >> 
  >> use File::Slurp qw( edit_file ) ;
  >> 
  >> edit_file { s/'password'/'redacted'/g } '/path/to/iypjx_2.html' ;
  >> 
  >> done.

  CD> ...in a way that unnecessarily ruins this line:

  CD> $ftp->login($username, $password)       or die "Couldn't login\n";

huh??

  >> to the OP: next time stop with the nonsense, the quine, the logs, and
  >> just say you want to edit a file in place. pretty simple concept but you
  >> said everything BUT that.

  CD> Well, uri, I just came down from the mountains, and I've decided to
  CD> turn over a few new leafs.  Maybe one of them could be with you.
  CD> Would you like me to try File::Slurp and see if it can work into my
  CD> own meaningful projects?

huh??

you can use the module any way you want and anywhere you want. it is on
cpan for the world to enjoy.

  CD> If I did without your permission, you could say, "I never asked you to
  CD> touch this software."

well, you can USE it but you can't modify it on cpan as i own it. if you
come up with useful patches that i approve, i may add them. or you could
fork the module and make your own version.

  CD> I hope not to sound ironic, combative, all that.  Cheers,

no. but you do sound like you need to learn about cpan.

uri


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

Date: Wed, 01 Aug 2012 20:53:57 -0600
From: Cal Dershowitz <cal@example.invalid>
Subject: Re: a regex for removing a password in a source listing
Message-Id: <cvCdna3T0aBYdoTNnZ2dnUVZ_vGdnZ2d@supernews.com>

On 07/31/2012 10:29 PM, Uri Guttman wrote:
>>>>>> "WB" == Wolf Behrenhoff<NoSpamPleaseButThisIsValid3@gmx.net>  writes:
>
>    >>  while (<$gh>) {
>
>    WB>  This is while (defined($_ =<$gh>)), i.e. you now have a new value in $_
>    WB>  corresponding to a line. This is a copy! So modifying $_ doesn't do
>    WB>  anything to the file!
>
> wow. the OP had a massively odd view of rw files.

I don't think I have enough of an idea about them for it to be odd.  Of 
course, when I saw the output, I knew I'd just put my data through a 
chipper, where the resulting chips may have been the sum total of input 
and output, but like I say, it was a chipper.
>
>
>    WB>  What about perl's in-place edit? See perldoc perlrun!
>
>    WB>  Just run
>    WB>  perl -pi -e 's/password/redacted/g' /path/to/iypjx_2.html
>
>    WB>  or maybe
>    WB>  perl -pi -e "s/'password'/'redacted'/g" /path/to/iypjx_2.html
>    WB>  if you only want to replace the password if it is between single quotes.
>
> since he is doing this in a script and not the command line, edit_file
> or edit_file_lines from File::Slurp with do that easily
>
> use File::Slurp qw( edit_file ) ;
>
> 	edit_file { s/'password'/'redacted'/g } '/path/to/iypjx_2.html' ;
>
> done.

 ...in a way that unnecessarily ruins this line:

$ftp->login($username, $password)       or die "Couldn't login\n";
>
> to the OP: next time stop with the nonsense, the quine, the logs, and
> just say you want to edit a file in place. pretty simple concept but you
> said everything BUT that.
>
> uri

Well, uri, I just came down from the mountains, and I've decided to turn 
over a few new leafs.  Maybe one of them could be with you.  Would you 
like me to try File::Slurp and see if it can work into my own meaningful 
projects?

If I did without your permission, you could say, "I never asked you to 
touch this software."

I hope not to sound ironic, combative, all that.  Cheers,
-- 
Cal


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

Date: Wed, 01 Aug 2012 22:13:56 +0700
From: Ivan Shmakov <oneingray@gmail.com>
Subject: i18n for netnews
Message-Id: <866292skzv.fsf_-_@gray.siamics.net>

>>>>> Shmuel (Seymour J ) Metz <spamtrap@library.lspace.org.invalid> writes:
>>>>> Ivan Shmakov <oneingray@gmail.com> said:

	[Cross-posting and setting Followup-To: news:news.misc, for
	obvious reasons.]

 >> (In particular, I'm planning to work on a "NNTP server"
 >> implementation next year, and it's likely that it will reject
 >> messages with non-ASCII headers outright.)

 > That's appropriate for now, but keep your eye on the
 > internationalization efforts at IETF.  There is an RFC set for
 > internationalized e-mail, and news is the obvious next step;

	As of RFC 5536 (published November 2009), it's /allowed/ to use
	national characters in Netnews article headers, /provided/ that
	RFC 2047 is used to encode them in 7-bit ASCII.  For instance:

Subject: al =?utf-8?Q?=C4=89iu?= abonantoj 

	is perfectly valid, while:

Subject: al \xE6iu abonantoj 

	(where \xE6 is the octet to be interpreted using a particular,
	unspecified encoding; the form I was complaining to) is not.

 > I would assume that such an enhancement will include a new capability
 > in the registry described in RFC 3977, 3.3.4. Initial IANA Register.

-- 
FSF associate member #7257	http://sf-day.org/


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

Date: 31 Jul 2012 17:36:38 -0400
From: dkcombs@panix.com (David Combs)
Subject: Man, has this newsgroup shrunk.  Why?  Where gone to?
Message-Id: <jv9j56$im6$1@panix1.panix.com>

It's fairly obvious that this group has really shrunk over
the last year or so.

So, what's up?

Surely, perl usage isn't down.

So where are the problems and answers (via perl-answer gurus)
operating from now?  Some web site?  (Because gen-x doesn't
like newsgroups?)

Just wondering.

David



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

Date: Tue, 31 Jul 2012 22:38:03 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: Man, has this newsgroup shrunk.  Why?  Where gone to?
Message-Id: <jv9mob$6t4$1@reader1.panix.com>

In article <jv9j56$im6$1@panix1.panix.com>,
David Combs <dkcombs@panix.com> wrote:
> (Because gen-x doesn't like newsgroups?)

Usenet in general is dying.  Some newsgroups died long ago; some
newsgroups, that had massive volume, now have a moderate volume.
Some newsgroups have an unusually worthwhile culture or unusually good
posters, but those newsgroups' death is merely going slower.

I've seen hardly any references to Usenet elsewhere in years.  I think
it has essentially no visibility, no mind space.  I suspect that it's
not that Gen X doesn't like newsgroups, it's that they've never heard
of newsgroups.

Google shovelling them into "Google Groups" and having an increasingly
lousy search system and interface didn't help.

-- 
Tim McDaniel, tmcd@panix.com


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

Date: Wed, 01 Aug 2012 00:54:11 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: Man, has this newsgroup shrunk.  Why?  Where gone to?
Message-Id: <87k3xjlc64.fsf@sapphire.mobileactivedefense.com>

dkcombs@panix.com (David Combs) writes:
> It's fairly obvious that this group has really shrunk over
> the last year or so.
>
> So, what's up?

Too many nasty old men and fans of nasy old men.


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

Date: Wed, 1 Aug 2012 11:16:24 -0500
From: "E.D.G." <edgrsprj@ix.netcom.com>
Subject: Time Question
Message-Id: <JsednYi0XZ8Oy4TNnZ2dnUVZ_tCdnZ2d@earthlink.com>

TIME QUESTION

The latest version of ActiveState Perl is being used on one computer.  And 
ActiveState 5.10 is being used on another as it needs to have a large number 
of special modules running.

Question:  Is there a Perl routine in either of those versions or some 
module that will let you work with dates as if they were numbers?

The goal is to be able to tell what the UTC date and time are (ex. 
2012/08/01 12:34:56) that is say 130 days and 4 hours ahead of some date 
such as today or 30 days from now.



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

Date: Wed, 01 Aug 2012 18:34:58 +0200
From: Wolf Behrenhoff <NoSpamPleaseButThisIsValid3@gmx.net>
Subject: Re: Time Question
Message-Id: <50195ab3$0$6555$9b4e6d93@newsspool4.arcor-online.net>

Am 01.08.2012 18:16, schrieb E.D.G.:
> TIME QUESTION
> 
> The goal is to be able to tell what the UTC date and time are (ex. 
> 2012/08/01 12:34:56) that is say 130 days and 4 hours ahead of some date 
> such as today or 30 days from now.

perldoc Date::Calc

- Wolf




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

Date: Wed, 1 Aug 2012 20:44:01 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Time Question
Message-Id: <1hdoe9-u151.ln1@anubis.morrow.me.uk>


Quoth Wolf Behrenhoff <NoSpamPleaseButThisIsValid3@gmx.net>:
> Am 01.08.2012 18:16, schrieb E.D.G.:
> > TIME QUESTION
> > 
> > The goal is to be able to tell what the UTC date and time are (ex. 
> > 2012/08/01 12:34:56) that is say 130 days and 4 hours ahead of some date 
> > such as today or 30 days from now.
> 
> perldoc Date::Calc

IMHO it's better to just go with DateTime. While there are other modules
which are smaller and (in principle) faster, I don't believe any of them
Do Everything Right the way DateTime does. Having to convert your code
from one API to another when you find you've hit a case your chosen
module doesn't handle properly is probably worth avoiding.

Ben



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

Date: Wed, 01 Aug 2012 20:14:36 -0600
From: Cal Dershowitz <cal@example.invalid>
Subject: using a help file to populate ftp values
Message-Id: <HYGdnRvf5ewQf4TNnZ2dnUVZ_vWdnZ2d@supernews.com>

On 08/01/2012 04:11 AM, Wolf Behrenhoff wrote:
> Am 01.08.2012 08:00, schrieb Cal Dershowitz:
>>       if (/\$domain\) {
>>           print "matched\n";
>>           $word =~ m/
>
> This is the whole match! From the first / right after the if to the
> second one which only appears 2 lines later.
>
> You simply forgot to end the match with / and used the \ instead.
>
>

Thanks, wolf.  I get times where I can't see the difference between the 
forward and backslash.  I call it "Dual-Boot Fatigue Syndrome."

$ perl safe_post4.pl
matched
my $domain = 'www.bedrock.com';
word is www.bedrock.com
matched
my $username = 'barney';
word is barney
matched
my $password = 'rocks';
word is rocks
$ cat safe_post4.pl
#!/usr/bin/perl -w
use strict;
use 5.010;
use Net::FTP;
my ( $domain, $username, $password );
my $identity_file = 'ftp_passwords_1.txt';
my ( @lines, $word );
open( my $gh, '<', $identity_file )
   or die("Can't open $identity_file  for writing: $!");
chomp( @lines = <$gh> );
close $gh;

foreach (@lines) {
     if (/\$domain/) {
         print "matched\n";
         print $_ . "\n";
         m/'(.*)'/;
         $domain = $1;
         print "word is $domain\n";
     }
}

foreach (@lines) {
     if (/\$username/) {
         print "matched\n";
         print $_ . "\n";
         m/'(.*)'/;
         $username = $1;
         print "word is $username\n";
     }
}

foreach (@lines) {
     if (/\$password/) {
         print "matched\n";
         print $_ . "\n";
         m/'(.*)'/;
         $password = $1;
         print "word is $password\n";
     }
}

$

This works, but I wouldn't be too wild about seeing it included in all 
my ftp scripts.

Q1)  How could one read the word $domain or anything with a dollar sign 
on it in the help file and then declare it at top scope in the script?


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

Date: Thu, 2 Aug 2012 06:53:40 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: using a help file to populate ftp values
Message-Id: <48hpe9-epf1.ln1@anubis.morrow.me.uk>


Quoth Cal Dershowitz <cal@example.invalid>:
> 
> $ perl safe_post4.pl
> matched
> my $domain = 'www.bedrock.com';
> word is www.bedrock.com
> matched
> my $username = 'barney';
> word is barney
> matched
> my $password = 'rocks';

I hope this isn't your real password...

> word is rocks
> $ cat safe_post4.pl
> #!/usr/bin/perl -w
> use strict;
> use 5.010;
> use Net::FTP;
> my ( $domain, $username, $password );
> my $identity_file = 'ftp_passwords_1.txt';
> my ( @lines, $word );
> open( my $gh, '<', $identity_file )
>    or die("Can't open $identity_file  for writing: $!");

*Reading*. If you use 'autodie' it will get this right for you.

> chomp( @lines = <$gh> );
> close $gh;
> 
> foreach (@lines) {
>      if (/\$domain/) {
>          print "matched\n";
>          print $_ . "\n";
>          m/'(.*)'/;
>          $domain = $1;
>          print "word is $domain\n";
>      }
> }
> 
> foreach (@lines) {

Why are you iterating over the lines multiple times? You can do several
matches in one loop.

Why have you made your configuration file format look like Perl? Perl is
not a particularly easy language to parse. I would suggest something
simpler; perhaps

    domain: ftp.foo.com
    username: cal
    password: xxxx

which you could then read into a hash something like this:

    my %info;
    {
        open my $INFO, "<", ...;
        while (<$INFO>) {
            chomp;
            my ($k, $v) = /^(\w+):\s+(.*)$/ 
                or die "Incorrect format for password file: [$_]";
            $info{$k} = $v;
        }
        # no need to close, perl will do this for you when $INFO goes
        # out of scope
    }

(There are certainly more concise ways of doing this--I might use map
and File::Slurp--but this is simple and straightforward.)

You could also use one of the existing config file parsers, perhaps
YAML::XS or Config::Simple, though for something this trivial it
probably isn't worth it.

> Q1)  How could one read the word $domain or anything with a dollar sign 
> on it in the help file and then declare it at top scope in the script?

What is 'the help file'? This file you've put your passwords in?

You can't, at least not without trickery of some sort. The whole point
of lexical ('my') variables is that they have to be declared where you
can see them, in the file (and scope) you're looking at. You could
require a file which set some globals, but that's not a good idea for
all the usual reasons.

Ben



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

Date: Wed, 01 Aug 2012 20:17:49 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: using a help file to populate ftp values
Message-Id: <aasj18p76rtqu3irc3jpc9l21dudcaj7pl@4ax.com>

Cal Dershowitz <cal@example.invalid> wrote:
>Q1)  How could one read the word $domain or anything with a dollar sign 
>on it in the help file and then declare it at top scope in the script?

Are you looking for a template system?

jue


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

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 3748
***************************************


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