Skip to search.

Breaking News Visit Yahoo! News for the latest.

×Close this window

perl-beginner · Perl Beginners Mailing List

The Yahoo! Groups Product Blog

Check it out!

Group Information

  • Members: 3765
  • Category: Perl
  • Founded: Aug 2, 1998
  • Language: English
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Messages

Advanced
Messages Help
Messages 26613 - 26648 of 27459   Oldest  |  < Older  |  Newer >  |  Newest
Messages: Show Message Summaries Sort by Date ^  
#26613 From: "Robert Lee Binkley" <leebinkley@...>
Date: Fri May 29, 2009 10:08 pm
Subject: RE: [PBML] RE: X days old
leebinkley
Send Email Send Email
 
#!/usr/bin/perl

# delold.pl - delete old files

use strict;
use warnings;
use Win32::Autoglob;
use Getopt::Long;

$| = 1;

sub print_usage;
sub abort_usage;

# option defaults
my $days_back    = 10;
my $test_flag    = 0;
my $verbose_flag = 0;
my $quiet_flag   = 0;

# get options
GetOptions (
     'days=i'  => \$days_back,
     'test'    => \$test_flag,
     'verbose' => \$verbose_flag,
     'quiet'   => \$quiet_flag,
     'usage'   => sub {print_usage; exit 1},
) or abort_usage "Invalid option";

my $time = time();

my $files_to_delete = 0;
my $files_total     = 0;
my $files_failed    = 0;

FILE:
for my $file (@ARGV) {

     # must exist, must be a plain old file
     next FILE if !-e $file;
     next FILE if !-f $file;

     $files_total++;

     # modified age in days
     my ($mtime) = (stat($file))[9];
     my $modified_age = ($time - $mtime) / (3600 * 24);

     # skip if too young
     next FILE if $modified_age < $days_back;

     $files_to_delete++;

     if ($test_flag || $verbose_flag) {
         printf "Age: %-6.1f  File: %s\n",
             $modified_age,
             $file;
     }

     # skip if we are testing
     next FILE if $test_flag;

     # delete the file
     if (!unlink $file) {
         warn "Failed to delete file $file\n";
         $files_failed++;
     }

}

if ($test_flag) {
     print "\nTest Flag is set, no deletes done!\n";
}

my $files_remaining = $files_total - $files_to_delete + $files_failed;

if (!$quiet_flag || $test_flag) {
     print "\n";
     print "Total files:      $files_total\n";
     print "Files to delete:  $files_to_delete\n";
     print "Failed to delete: $files_failed\n";
     print "Files remaining:  $files_remaining\n";
}

exit 1;

sub abort_usage {
     print STDERR join("\n", @_), "\n" if @_;
     print_usage;
     exit 0;
}

sub print_usage {
     print STDERR <<END;
Usage: delold.pl [Options] files...
Options:
     --days n      - Set age of files to keep.
                     Files over "days" old will be deleted.
                     Default is 10 days.
     --test        - Print file names to be deleted with age,
                     but do not actually delete.
                     Default is false.
     --verbose     - Print file name and age while deleting.
                     Default is false.
     --quiet       - Suppress printing of totals after deleting.
                     Default is false.
     --usage       - print this message and exit
END
}


-----Original Message-----
From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com]
On Behalf Of Shlomi Fish
Sent: Friday, May 29, 2009 8:15 AM
To: perl-beginner@yahoogroups.com
Subject: Re: [PBML] RE: X days old

On Friday 29 May 2009 14:31:29 Wittich,Douglas G wrote:
> ________________________________
> From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com]
> On Behalf Of Dukelow, Don Sent: Monday, May 18, 2009 1:10 PM
> To: perl-beginner@yahoogroups.com
> Subject: [PBML] X days old
>
>
>
>
> Is there a Perl module that has a command that will remove all files that
> are over X days old in a directory? Or will I have to write something?
>
> I've try using the UNIX "find" command from Perl but that is nasty.
>
> qx("/bin/find $data_dir -mtime $days -exec rm {} \;");
>

You should use File::Find ( http://search.cpan.org/perldoc?File::Find ),
File::Find::Object:
http://www.shlomifish.org/open-source/projects/File-Find-Object/

, File::Find::Rule (on the CPAN) or something. They are the Perl eqvuivalent

to the UNIX find command. Let me know if you need more help.

Are you interested in deleting from a directory (without the
sub-directories)
or throughout an entire directory tree?

Regards,

	 Shlomi Fish

--
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Freecell Solver - http://fc-solve.berlios.de/

God gave us two eyes and ten fingers so we will type five times as much as
we
read.



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

Unsubscribing info is here:
http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo! Groups Links

#26614 From: merlyn@...
Date: Sat May 30, 2009 3:35 am
Subject: Re: [PBML] RE: X days old
merlynstoneh...
Send Email Send Email
 
>>>>> "Robert" == Robert Lee Binkley <leebinkley@...> writes:

Robert>     next FILE if !-e $file;
Robert>     next FILE if !-f $file;

If it's not -f, it's not -e.  No point in checking both.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

#26615 From: "edu_kumar" <sarat.beesa@...>
Date: Tue Jun 2, 2009 12:59 pm
Subject: Evaluating the expression in if VS While
edu_kumar
Send Email Send Email
 
Hi all,

I'm a beginner in Perl and I slowly started writing small programs in it. While
I was playing with the if and while loops in Perl, I got into a really weird
scenario. Please look at the snippet of code below..

-----------------------Program starts here-------------------------
#!/usr/bin/perl

$index = 0;
$s = 1;
if($s<1){
print("Hey, in perl its different man ! ");
}
else
{
print("The whole world stays as is..! \n");
}

while($index <1) {
print ("$index < 1 is true!  \n");
$index += 0.1;

print ("$index\n");

---------------------------Program ends here -----------

the output I got is pretty weird. Here's the output...

-- This is the output of the if statement and it looks very fine to me.

The whole world stays as is..!

-- However, this is the output of the While loop. Strangely the condition ( 1 <
1 ) evaluates to false in case of if loop and true in case of while loop.

0 < 1 is true!
0.1
0.1 < 1 is true!
0.2
0.2 < 1 is true!
0.3
0.3 < 1 is true!
0.4
0.4 < 1 is true!
0.5
0.5 < 1 is true!
0.6
0.6 < 1 is true!
0.7
0.7 < 1 is true!
0.8
0.8 < 1 is true!
0.9
0.9 < 1 is true!
1
1 < 1 is true!
1.1


Obviously I might be doing something stupid here and I wasn't able to figure it
out. can someone point me here in the right direction ? given below is my perl
version..

------------------------------------------------
bash-3.00$ /usr/bin/perl -version

This is perl, v5.8.4 built for i86pc-solaris-64int
(with 29 registered patches, see perl -V for more detail)

Copyright 1987-2004, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'.  If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.

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

#26616 From: "Charles K. Clarkson" <cclarkson@...>
Date: Tue Jun 2, 2009 1:51 pm
Subject: Re: [PBML] Evaluating the expression in if VS While
charlesclarkson
Send Email Send Email
 
edu_kumar wrote:


> Strangely the condition ( 1 < 1 ) evaluates to false

Generally, algorithms should avoid comparing integer values to
floating point values. Now you know why.



HTH,

Charles Clarkson
--
Mobile Home Investor
Free Market Advocate
Programmer

I'm not really a smart person. I just play one on the Internet.

Stephenville, TX
http://www.clarksonenergyhomes.com/wordpress/about/
http://twitter.com/CharlesClarkson
+1 (254) 968-8328

#26617 From: merlyn@...
Date: Tue Jun 2, 2009 2:17 pm
Subject: Re: [PBML] Evaluating the expression in if VS While
merlynstoneh...
Send Email Send Email
 
>>>>> "edu" == edu kumar <sarat.beesa@...> writes:

edu> while($index <1) {
edu> print ("$index < 1 is true!  \n");
edu> $index += 0.1;

edu> print ("$index\n");

edu> ---------------------------Program ends here -----------

edu> the output I got is pretty weird. Here's the output...

This is one of the FAQs.  It'd be good to get familiar with the
Perl FAQ, especially if you're a beginner.

In particular, "perldoc -q int" says:

....
Found in /usr/libdata/perl5/pod/perlfaq4.pod
   Why is int() broken?
     Your int() is most probably working just fine. It's the numbers that
     aren't quite what you think.

     First, see the above item "Why am I getting long decimals (eg,
     19.9499999999999) instead of the numbers I should be getting (eg,
     19.95)?".

     For example, this

         print int(0.6/0.2-2), "\n";

     will in most computers print 0, not 1, because even such simple numbers
     as 0.6 and 0.2 cannot be presented exactly by floating-point numbers.
     What you think in the above as 'three' is really more like
     2.9999999999999995559.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

#26618 From: "Robert Lee Binkley" <leebinkley@...>
Date: Wed Jun 3, 2009 5:00 pm
Subject: RE: [PBML] Evaluating the expression in if VS While
leebinkley
Send Email Send Email
 
You are adding after the fact and printing then it goes back to the
test. If I move up the print to before the print true, here is the output:

[C:/Common] aapl013j
The whole world stays as is..!
0
0 < 1 is true!
0.1
0.1 < 1 is true!
0.2
0.2 < 1 is true!
0.3
0.3 < 1 is true!
0.4
0.4 < 1 is true!
0.5
0.5 < 1 is true!
0.6
0.6 < 1 is true!
0.7
0.7 < 1 is true!
0.8
0.8 < 1 is true!
0.9
0.9 < 1 is true!
1
1 < 1 is true!



     Which is what you are after I believe.....





From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com]
On Behalf Of edu_kumar
Sent: Tuesday, June 02, 2009 8:00 AM
To: perl-beginner@yahoogroups.com
Subject: [PBML] Evaluating the expression in if VS While








Hi all,

I'm a beginner in Perl and I slowly started writing small programs in it.
While I was playing with the if and while loops in Perl, I got into a really
weird scenario. Please look at the snippet of code below..

-----------------------Program starts here-------------------------
#!/usr/bin/perl

$index = 0;
$s = 1;
if($s<1){
print("Hey, in perl its different man ! ");
}
else
{
print("The whole world stays as is..! \n");
}

while($index <1) {
print ("$index < 1 is true! \n");
$index += 0.1;

print ("$index\n");

---------------------------Program ends here -----------

the output I got is pretty weird. Here's the output...

-- This is the output of the if statement and it looks very fine to me.

The whole world stays as is..!

-- However, this is the output of the While loop. Strangely the condition (
1 < 1 ) evaluates to false in case of if loop and true in case of while
loop.

0 < 1 is true!
0.1
0.1 < 1 is true!
0.2
0.2 < 1 is true!
0.3
0.3 < 1 is true!
0.4
0.4 < 1 is true!
0.5
0.5 < 1 is true!
0.6
0.6 < 1 is true!
0.7
0.7 < 1 is true!
0.8
0.8 < 1 is true!
0.9
0.9 < 1 is true!
1
1 < 1 is true!
1.1

Obviously I might be doing something stupid here and I wasn't able to figure
it out. can someone point me here in the right direction ? given below is my
perl version..

------------------------------------------------
bash-3.00$ /usr/bin/perl -version

This is perl, v5.8.4 built for i86pc-solaris-64int
(with 29 registered patches, see perl -V for more detail)

Copyright 1987-2004, Larry Wall

Perl may be copied only under the terms of either the Artistic License or
the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.

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





[Non-text portions of this message have been removed]

#26619 From: "edu_kumar" <sarat.beesa@...>
Date: Wed Jun 3, 2009 11:49 am
Subject: Re: Evaluating the expression in if VS While
edu_kumar
Send Email Send Email
 
Hey Charles,

Thanks very much for your response. It truly an eye opener, i guess i'm still
thinking of it as Java since I was more of a java programmer till now.

I converted those numbers into integers explicitly and it worked properly as
expected.

Thanks again, I really appreciate it.


--- In perl-beginner@yahoogroups.com, "Charles K. Clarkson" <cclarkson@...>
wrote:
>
> edu_kumar wrote:
>
>
> > Strangely the condition ( 1 < 1 ) evaluates to false
>
> Generally, algorithms should avoid comparing integer values to
> floating point values. Now you know why.
>
>
>
> HTH,
>
> Charles Clarkson
> --
> Mobile Home Investor
> Free Market Advocate
> Programmer
>
> I'm not really a smart person. I just play one on the Internet.
>
> Stephenville, TX
> http://www.clarksonenergyhomes.com/wordpress/about/
> http://twitter.com/CharlesClarkson
> +1 (254) 968-8328
>

#26620 From: merlyn@...
Date: Wed Jun 3, 2009 7:18 pm
Subject: Re: [PBML] Re: Evaluating the expression in if VS While
merlynstoneh...
Send Email Send Email
 
>>>>> "edu" == edu kumar <sarat.beesa@...> writes:

edu> Thanks very much for your response. It truly an eye opener, i guess i'm
edu> still thinking of it as Java since I was more of a java programmer till
edu> now.

Actually, that floating point issue is true for *all* languages.

Perl is doing this as accurately as C does it, which is also how
Java and Fortran do it.  And Python.  And Ruby.

This is a problem of *all* Floating Point values that use the modern accepted
"IEEE 754" representation.  Namely, that 0.1 is not a precise number in
binary.  So 10 times that is not precisely 1.0, necessarily.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

#26621 From: merlyn@...
Date: Wed Jun 3, 2009 7:25 pm
Subject: Re: [PBML] Evaluating the expression in if VS While
merlynstoneh...
Send Email Send Email
 
>>>>> "Charles" == Charles K Clarkson <cclarkson@...> writes:

Charles> Generally, algorithms should avoid comparing integer values to
Charles> floating point values. Now you know why.

Even comparing floats to floats might hurt.

The better thing to repeat as a mantra is:

     Floating point values are *always* an approximation.
     Floating point values are *always* an approximation.
     Floating point values are *always* an approximation.
     Floating point values are *always* an approximation.

Except in a few rare cases, but there's nearly an infinite number
of cases that outweigh them. :)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

#26622 From: Kelly Jones <kelly.terry.jones@...>
Date: Thu Jun 4, 2009 1:20 am
Subject: Perl floating point addition oddness
kelly.terry.jones@...
Send Email Send Email
 
perl -le 'printf("%f %f %f\n", 4294967295, 2147483647*2**32,
2147483647*2**32+4294967295)'

4294967295.000000 9223372032559808512.000000 9223372036854775808.000000

Why? The answer is really 9223372036854775807 (one number lower), and
it's obvious that adding 2 and 5 in the units column should yield a 7
in the sum's unit column.

Roundoff error? Bug? How do I work around it?

--
We're just a Bunch Of Regular Guys, a collective group that's trying
to understand and assimilate technology. We feel that resistance to
new ideas and technology is unwise and ultimately futile.

#26623 From: merlyn@...
Date: Thu Jun 4, 2009 1:40 am
Subject: Re: [PBML] Perl floating point addition oddness
merlynstoneh...
Send Email Send Email
 
>>>>> "Kelly" == Kelly Jones <kelly.terry.jones@...> writes:

Kelly> perl -le 'printf("%f %f %f\n", 4294967295, 2147483647*2**32,
Kelly> 2147483647*2**32+4294967295)'

Kelly> 4294967295.000000 9223372032559808512.000000 9223372036854775808.000000

Kelly> Why? The answer is really 9223372036854775807 (one number lower), and
Kelly> it's obvious that adding 2 and 5 in the units column should yield a 7
Kelly> in the sum's unit column.

Kelly> Roundoff error? Bug? How do I work around it?

If you're not just trolling (since we just talked about floating
point being approximate in this mailing list):

     use Math::BigInt;
     $a = Math::BigInt->new('4294967295');
     $b = Math::BigInt->new('2147483647');

     print "$_\n" for $a, $b*2**32, $b*2**32+$a;

==>

     4294967295
     9223372032559808512
     9223372036854775807

And show me a C compiler that can do that correctly.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

#26624 From: Kelly Jones <kelly.terry.jones@...>
Date: Thu Jun 4, 2009 1:52 am
Subject: Re: [PBML] Perl floating point addition oddness
kelly.terry.jones@...
Send Email Send Email
 
On 6/3/09, Randal L. Schwartz <merlyn@...> wrote:
>>>>>> "Kelly" == Kelly Jones <kelly.terry.jones@...> writes:
>
> Kelly> perl -le 'printf("%f %f %f\n", 4294967295, 2147483647*2**32,
> Kelly> 2147483647*2**32+4294967295)'
>
> Kelly> 4294967295.000000 9223372032559808512.000000
> 9223372036854775808.000000
>
> Kelly> Why? The answer is really 9223372036854775807 (one number lower), and
> Kelly> it's obvious that adding 2 and 5 in the units column should yield a 7
> Kelly> in the sum's unit column.
>
> Kelly> Roundoff error? Bug? How do I work around it?
>
> If you're not just trolling (since we just talked about floating
> point being approximate in this mailing list):
>
>     use Math::BigInt;
>     $a = Math::BigInt->new('4294967295');
>     $b = Math::BigInt->new('2147483647');
>
>     print "$_\n" for $a, $b*2**32, $b*2**32+$a;
>
> ==>
>
>     4294967295
>     9223372032559808512
>     9223372036854775807
>
> And show me a C compiler that can do that correctly.

Not trolling. I'm trying to convert node latitude/longitudes in
openstreetmap.org into 63-bit INTs for sqlite3 rowid number.

I'm on a 32-bit machine, so %u doesn't help.

After interleaving, I end up w/ $str, a 64-character long string of 0s
and 1s (the first character is always 0, so it's really a 63-bit INT)

I tried 'unpack("N",pack("B64",$str))' but that failed.

So I ended up doing:

$low = substr($str,32,32);
$high = substr($str,0,32);
$nlow = unpack("N",pack("B32",$low));
$nhigh = unpack("N",pack("B32",$high));

and then calculating $nlow+$nhigh*2**32

I can use BigInt on $nlow and $nhigh as you describe (in fact, I
googled "perl unlimited precision" and was about to do this anyway),
but is there a better approach overall?

--
We're just a Bunch Of Regular Guys, a collective group that's trying
to understand and assimilate technology. We feel that resistance to
new ideas and technology is unwise and ultimately futile.

#26625 From: merlyn@...
Date: Thu Jun 4, 2009 2:00 am
Subject: Re: [PBML] Perl floating point addition oddness
merlynstoneh...
Send Email Send Email
 
>>>>> "Kelly" == Kelly Jones <kelly.terry.jones@...> writes:

Kelly> Not trolling. I'm trying to convert node latitude/longitudes in
Kelly> openstreetmap.org into 63-bit INTs for sqlite3 rowid number.

The problem is that Perl uses doubles inside for everything, including
integers, and the integer part of the floating point number is somewhat
limited, as you see (I think it's only 56 bits).  That's why Math::BigInt is
needed here.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

#26626 From: murali iyer <psmiyer@...>
Date: Sun Jun 7, 2009 11:59 am
Subject: Un-subscibe my ID
psmiyer
Send Email Send Email
 
 




[Non-text portions of this message have been removed]

#26627 From: Jeff Pinyan <japhy.734@...>
Date: Sun Jun 7, 2009 3:45 pm
Subject: Re: [PBML] Un-subscibe my ID
evilffej
Send Email Send Email
 
In case you didn't see (and I assume you didn't):

To unsubscribe from this group, send an email to:
>    perl-beginner-unsubscribe@yahoogroups.com
>

--
The Cross Reference - http://thecrossreference.blogspot.com/
Critical Mass (The Science of the Liturgy) -
http://romanliturgy.blogspot.com/

[Mary said,] "Do whatever he tells you." ~ John 2:5


[Non-text portions of this message have been removed]

#26629 From: "Dukelow, Don" <dukelow@...>
Date: Tue Jun 9, 2009 1:38 pm
Subject: Perl SSH issues
dondukelow
Send Email Send Email
 
I've used Perl SSH on a number of occasions in the past but nothing series.  Now
I need to get series, does anyone know some good web sights I can go to get some
good how to's in Perl SSH?  Plus some good examples of programs?

-----
Don Dukelow

#26630 From: "Robert Lee Binkley" <leebinkley@...>
Date: Tue Jun 9, 2009 10:44 pm
Subject: RE: [PBML] Perl SSH issues
leebinkley
Send Email Send Email
 
If all you need to do is run a command on a remote host then



my @host_files_in_tmp = qx(ssh user@host ls /tmp);



#!/usr/bin/perl

use strict;
use warnings;
use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use Net::SSH::Perl;
use Data::Dumper;

$|++;

my $imap1 = 'imap1';
my %params = (debug => 1, protocol => 2);

print header(),
       start_html(),
       "creating ssh object: ", scalar localtime, br;

warningsToBrowser(1);

my $ssh_imap1 = Net::SSH::Perl->new($imap1, %params) || die "can't ssh $!";
print "ssh object created: ", scalar localtime, "<br>$/";

print "logging in: ", scalar localtime, br;
$ssh_imap1->login('me');
print "logged in: ", scalar localtime, br;

my ($stdout, $stderr, $exit) = $ssh_imap1->cmd('pwd');
$stdout =~ s/\n/<br>/g;

print "<br>$stdout",
       end_html();



Hope this helps



From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com]
On Behalf Of Dukelow, Don
Sent: Tuesday, June 09, 2009 8:39 AM
To: perl-beginner@yahoogroups.com
Subject: [PBML] Perl SSH issues








I've used Perl SSH on a number of occasions in the past but nothing series.
Now I need to get series, does anyone know some good web sights I can go to
get some good how to's in Perl SSH? Plus some good examples of programs?

-----
Don Dukelow





[Non-text portions of this message have been removed]

#26636 From: Shlomi Fish <shlomif@...>
Date: Tue Jun 2, 2009 1:51 pm
Subject: Re: [PBML] Evaluating the expression in if VS While
shlomif2
Send Email Send Email
 
On Tuesday 02 June 2009 15:59:50 edu_kumar wrote:
> Hi all,
>
> I'm a beginner in Perl and I slowly started writing small programs in it.
> While I was playing with the if and while loops in Perl, I got into a
> really weird scenario. Please look at the snippet of code below..
>
> -----------------------Program starts here-------------------------
> #!/usr/bin/perl
>
> $index = 0;
> $s = 1;
> if($s<1){
> print("Hey, in perl its different man ! ");
> }
> else
> {
> print("The whole world stays as is..! \n");
> }
>
> while($index <1) {
> print ("$index < 1 is true!  \n");
> $index += 0.1;
>
> print ("$index\n");
>
> ---------------------------Program ends here -----------
>

A few notes about your code:

1. You're missing "use strict;" and "use warnings;". Please add them.

2. Your first print is missing a "\n".

3. You are missing the closing right brace of the while loop.

> the output I got is pretty weird. Here's the output...
>
> -- This is the output of the if statement and it looks very fine to me.
>
> The whole world stays as is..!
>
> -- However, this is the output of the While loop. Strangely the condition (
> 1 < 1 ) evaluates to false in case of if loop and true in case of while
> loop.

That's because you're using the variable $index in the while loop which is
initially set to 0. And 0 < 1. If you've used $s then the while loop would
have terminated.

Regards,

	 Shlomi Fish

>
> 0 < 1 is true!
> 0.1
> 0.1 < 1 is true!
> 0.2
> 0.2 < 1 is true!
> 0.3
> 0.3 < 1 is true!
> 0.4
> 0.4 < 1 is true!
> 0.5
> 0.5 < 1 is true!
> 0.6
> 0.6 < 1 is true!
> 0.7
> 0.7 < 1 is true!
> 0.8
> 0.8 < 1 is true!
> 0.9
> 0.9 < 1 is true!
> 1
> 1 < 1 is true!
> 1.1
>
>
> Obviously I might be doing something stupid here and I wasn't able to
> figure it out. can someone point me here in the right direction ? given
> below is my perl version..
>
> ------------------------------------------------
> bash-3.00$ /usr/bin/perl -version
>
> This is perl, v5.8.4 built for i86pc-solaris-64int
> (with 29 registered patches, see perl -V for more detail)
>
> Copyright 1987-2004, Larry Wall
>
> Perl may be copied only under the terms of either the Artistic License or
> the GNU General Public License, which may be found in the Perl 5 source
> kit.
>
> Complete documentation for Perl, including FAQ lists, should be found on
> this system using `man perl' or `perldoc perl'.  If you have access to the
> Internet, point your browser at http://www.perl.com/, the Perl Home Page.
>
> ------------------------------------------------

--
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Best Introductory Programming Language - http://xrl.us/bjn84

God gave us two eyes and ten fingers so we will type five times as much as we
read.

#26637 From: "Regina Miller" <rmiller@...>
Date: Wed Jun 17, 2009 3:29 pm
Subject: #ARGV and parameters with embedded spaces.
rmiller571957
Send Email Send Email
 
Hi,



My script to add a new user is below, written on solaris 10.



Running it using either of these two ways  (one with double quotes
around the second parameter and one with single quotes):

./adduser.sh TestAcct "John Smith" Law

./adduser.sh TestAcct 'John Smith' Law

My script thinks I have entered four parameters.



But when I run it using the following (with no embedded spaces):

./adduser.sh TestAcct JohnSmith Law

It then thinks I have entered three parameters.



How do I get a parameter that has embedded spaces to register as just
one parameter??



Thanks for any help,

Regina



Regina Miller

Lead Analyst, Grays Harbor County

(360) 249-4144  ext  457

rmiller@...





MY SCRIPT



eval "exec ctperl -S $0 $*"

     if $running_via_sh;

#$Id: adduser.sh,v 302.4 1995/07/21 16:29:18 nick Exp $

#require 'ctree.pl';

########################################################################
########

# %perl

# %width 80

# %title Add a New User

# %name adduser.sh



use strict;

use warnings;



die 'Usage:  adduser username "full name" group.  i.e. adduser testacct
"John Smith" Law'

    unless @ARGV == 3;



unless (system "useradd -g $ARGV[2] -d /home/$ARGV[0] -m -s /usr/bin/ksh
-c $ARGV[1] $ARGV[0]")

{

    system "passwd $ARGV[0]";

    exit;

}

print "Error.  User can not be added\n";





[Non-text portions of this message have been removed]

#26638 From: Shlomi Fish <shlomif@...>
Date: Wed Jun 17, 2009 3:43 pm
Subject: Re: [PBML] #ARGV and parameters with embedded spaces.
shlomif2
Send Email Send Email
 
On Wednesday 17 June 2009 18:29:40 Regina Miller wrote:
> Hi,
>

Hi!

First of all, you shouldn't use $ARGV[0] , $ARGV[1], etc. directly. Do:

{{{
my ($first_name, $last_name, $address) = @ARGV;
}}}

Which is a much more robust idea.

Secondly, look at the list form of system:

{{{
system("echo", "One two", "three four--five");
}}}

Hope it helps.

Regards,

	 Shlomi Fish


>
>
> My script to add a new user is below, written on solaris 10.
>
>
>
> Running it using either of these two ways  (one with double quotes
> around the second parameter and one with single quotes):
>
> ./adduser.sh TestAcct "John Smith" Law
>
> ./adduser.sh TestAcct 'John Smith' Law
>
> My script thinks I have entered four parameters.
>
>
>
> But when I run it using the following (with no embedded spaces):
>
> ./adduser.sh TestAcct JohnSmith Law
>
> It then thinks I have entered three parameters.
>
>
>
> How do I get a parameter that has embedded spaces to register as just
> one parameter??
>
>
>
> Thanks for any help,
>
> Regina
>
>
>
> Regina Miller
>
> Lead Analyst, Grays Harbor County
>
> (360) 249-4144  ext  457
>
> rmiller@...
>
>
>
>
>
> MY SCRIPT
>
>
>
> eval "exec ctperl -S $0 $*"
>
>     if $running_via_sh;
>
> #$Id: adduser.sh,v 302.4 1995/07/21 16:29:18 nick Exp $
>
> #require 'ctree.pl';
>
> ########################################################################
> ########
>
> # %perl
>
> # %width 80
>
> # %title Add a New User
>
> # %name adduser.sh
>
>
>
> use strict;
>
> use warnings;
>
>
>
> die 'Usage:  adduser username "full name" group.  i.e. adduser testacct
> "John Smith" Law'
>
>    unless @ARGV == 3;
>
>
>
> unless (system "useradd -g $ARGV[2] -d /home/$ARGV[0] -m -s /usr/bin/ksh
> -c $ARGV[1] $ARGV[0]")
>
> {
>
>    system "passwd $ARGV[0]";
>
>    exit;
>
> }
>
> print "Error.  User can not be added\n";
>
>
>
>
>
> [Non-text portions of this message have been removed]

--
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
What does "Zionism" mean? - http://xrl.us/bjn8u

God gave us two eyes and ten fingers so we will type five times as much as we
read.

#26639 From: "rmiller571957" <rmiller@...>
Date: Wed Jun 17, 2009 4:38 pm
Subject: Re: [PBML] #ARGV and parameters with embedded spaces.
rmiller571957
Send Email Send Email
 
Thanks very much for the advice on not using $ARGV's directly.
I will change my code to match.

But I'm not sure how your example of system("echo"...) applies to the embedded
blanks in a parameter issue.

What I would like is for the user to be able to use one word, or two words, or
three words (or even more, I guess) for the 2nd parameter.  That is:
"Smith"   or "Mary Smith"   or "Mary Ann Smith".
And I would like all of these to be picked up as just the single parameter,
regardless of how many embedded spaces there are between the quotes.

Thanks again for any help.
Regina

--- In perl-beginner@yahoogroups.com, Shlomi Fish <shlomif@...> wrote:
>
> On Wednesday 17 June 2009 18:29:40 Regina Miller wrote:
> > Hi,
> >
>
> Hi!
>
> First of all, you shouldn't use $ARGV[0] , $ARGV[1], etc. directly. Do:
>
> {{{
> my ($first_name, $last_name, $address) = @ARGV;
> }}}
>
> Which is a much more robust idea.
>
> Secondly, look at the list form of system:
>
> {{{
> system("echo", "One two", "three four--five");
> }}}
>
> Hope it helps.
>
> Regards,
>
>  Shlomi Fish
>
>
> >
> >
> > My script to add a new user is below, written on solaris 10.
> >
> >
> >
> > Running it using either of these two ways  (one with double quotes
> > around the second parameter and one with single quotes):
> >
> > ./adduser.sh TestAcct "John Smith" Law
> >
> > ./adduser.sh TestAcct 'John Smith' Law
> >
> > My script thinks I have entered four parameters.
> >
> >
> >
> > But when I run it using the following (with no embedded spaces):
> >
> > ./adduser.sh TestAcct JohnSmith Law
> >
> > It then thinks I have entered three parameters.
> >
> >
> >
> > How do I get a parameter that has embedded spaces to register as just
> > one parameter??
> >
> >
> >
> > Thanks for any help,
> >
> > Regina
> >
> >
> >
> > Regina Miller
> >
> > Lead Analyst, Grays Harbor County
> >
> > (360) 249-4144  ext  457
> >
> > rmiller@...
> >
> >
> >
> >
> >
> > MY SCRIPT
> >
> >
> >
> > eval "exec ctperl -S $0 $*"
> >
> >     if $running_via_sh;
> >
> > #$Id: adduser.sh,v 302.4 1995/07/21 16:29:18 nick Exp $
> >
> > #require 'ctree.pl';
> >
> > ########################################################################
> > ########
> >
> > # %perl
> >
> > # %width 80
> >
> > # %title Add a New User
> >
> > # %name adduser.sh
> >
> >
> >
> > use strict;
> >
> > use warnings;
> >
> >
> >
> > die 'Usage:  adduser username "full name" group.  i.e. adduser testacct
> > "John Smith" Law'
> >
> >    unless @ARGV == 3;
> >
> >
> >
> > unless (system "useradd -g $ARGV[2] -d /home/$ARGV[0] -m -s /usr/bin/ksh
> > -c $ARGV[1] $ARGV[0]")
> >
> > {
> >
> >    system "passwd $ARGV[0]";
> >
> >    exit;
> >
> > }
> >
> > print "Error.  User can not be added\n";
> >
> >
> >
> >
> >
> > [Non-text portions of this message have been removed]
>
> --
> -----------------------------------------------------------------
> Shlomi Fish       http://www.shlomifish.org/
> What does "Zionism" mean? - http://xrl.us/bjn8u
>
> God gave us two eyes and ten fingers so we will type five times as much as we
> read.
>

#26640 From: Shlomi Fish <shlomif@...>
Date: Wed Jun 17, 2009 4:48 pm
Subject: Re: [PBML] #ARGV and parameters with embedded spaces.
shlomif2
Send Email Send Email
 
On Wednesday 17 June 2009 19:38:04 rmiller571957 wrote:
> Thanks very much for the advice on not using $ARGV's directly.
> I will change my code to match.
>

It's not $ARGV - it's @ARGV. @ARGV is the entire array. $ARGV[$index] is an
individual element of it. There's also $ARGV in Perl which is a different
thing.

> But I'm not sure how your example of system("echo"...) applies to the
> embedded blanks in a parameter issue.
>
> What I would like is for the user to be able to use one word, or two words,
> or three words (or even more, I guess) for the 2nd parameter.  That is:
> "Smith"   or "Mary Smith"   or "Mary Ann Smith".
> And I would like all of these to be picked up as just the single parameter,
> regardless of how many embedded spaces there are between the quotes.
>

If you do, for example:

{{{
system("ls", "-l", "Hello there/");
}}}

Then ls will display the files under the "Hello there" directory with a space
in the path. You see - the list form of system treats each of the components
of the list as a single command-line argument, even if it contains spaces.

So this would be equivalent to doing the following commands in the shell:

{{{
ls -l "Hello there/"
ls -l 'Hello there/'
ls -l Hello\ there/
}}}

Regards,

	 Shlomi Fish

> Thanks again for any help.
> Regina
>
> --- In perl-beginner@yahoogroups.com, Shlomi Fish <shlomif@...> wrote:
> > On Wednesday 17 June 2009 18:29:40 Regina Miller wrote:
> > > Hi,
> >
> > Hi!
> >
> > First of all, you shouldn't use $ARGV[0] , $ARGV[1], etc. directly. Do:
> >
> > {{{
> > my ($first_name, $last_name, $address) = @ARGV;
> > }}}
> >
> > Which is a much more robust idea.
> >
> > Secondly, look at the list form of system:
> >
> > {{{
> > system("echo", "One two", "three four--five");
> > }}}
> >
> > Hope it helps.
> >
> > Regards,
> >
> >  Shlomi Fish
> >
> > > My script to add a new user is below, written on solaris 10.
> > >
> > >
> > >
> > > Running it using either of these two ways  (one with double quotes
> > > around the second parameter and one with single quotes):
> > >
> > > ./adduser.sh TestAcct "John Smith" Law
> > >
> > > ./adduser.sh TestAcct 'John Smith' Law
> > >
> > > My script thinks I have entered four parameters.
> > >
> > >
> > >
> > > But when I run it using the following (with no embedded spaces):
> > >
> > > ./adduser.sh TestAcct JohnSmith Law
> > >
> > > It then thinks I have entered three parameters.
> > >
> > >
> > >
> > > How do I get a parameter that has embedded spaces to register as just
> > > one parameter??
> > >
> > >
> > >
> > > Thanks for any help,
> > >
> > > Regina
> > >
> > >
> > >
> > > Regina Miller
> > >
> > > Lead Analyst, Grays Harbor County
> > >
> > > (360) 249-4144  ext  457
> > >
> > > rmiller@...
> > >
> > >
> > >
> > >
> > >
> > > MY SCRIPT
> > >
> > >
> > >
> > > eval "exec ctperl -S $0 $*"
> > >
> > >     if $running_via_sh;
> > >
> > > #$Id: adduser.sh,v 302.4 1995/07/21 16:29:18 nick Exp $
> > >
> > > #require 'ctree.pl';
> > >
> > > #######################################################################
> > ># ########
> > >
> > > # %perl
> > >
> > > # %width 80
> > >
> > > # %title Add a New User
> > >
> > > # %name adduser.sh
> > >
> > >
> > >
> > > use strict;
> > >
> > > use warnings;
> > >
> > >
> > >
> > > die 'Usage:  adduser username "full name" group.  i.e. adduser testacct
> > > "John Smith" Law'
> > >
> > >    unless @ARGV == 3;
> > >
> > >
> > >
> > > unless (system "useradd -g $ARGV[2] -d /home/$ARGV[0] -m -s
> > > /usr/bin/ksh -c $ARGV[1] $ARGV[0]")
> > >
> > > {
> > >
> > >    system "passwd $ARGV[0]";
> > >
> > >    exit;
> > >
> > > }
> > >
> > > print "Error.  User can not be added\n";
> > >
> > >
> > >
> > >
> > >
> > > [Non-text portions of this message have been removed]

--
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Interview with Ben Collins-Sussman - http://xrl.us/bjn8s

God gave us two eyes and ten fingers so we will type five times as much as we
read.

#26641 From: Chris Seip <ssvfmnx@...>
Date: Wed Jun 17, 2009 5:24 pm
Subject: Re: [PBML] #ARGV and parameters with embedded spaces.
ssvfmnx
Send Email Send Email
 
Hi Regina,
The problem is caused by the eval shell statement:
    eval "exec ctperl -S $0 $*"

When the shell runs your shell script, the quotation marks have preserved
the space in the "John Smith" command-line argument, but the quotation marks
are stripped away by the time the script "sees" that argument.  So, that
part of the $* argument list expands to John Smith (quoteless).  In the
expansion it is a single command line argument, but you are leaving the
space exposed on that eval exec... command line.  This splits the John Smith
into two args for the ctperl script.

Is the shell wrapper necessary around your ctperl script?

Chris



On Wed, Jun 17, 2009 at 9:48 AM, Shlomi Fish <shlomif@...> wrote:

> On Wednesday 17 June 2009 19:38:04 rmiller571957 wrote:
> > Thanks very much for the advice on not using $ARGV's directly.
> > I will change my code to match.
> >
>
> It's not $ARGV - it's @ARGV. @ARGV is the entire array. $ARGV[$index] is an
> individual element of it. There's also $ARGV in Perl which is a different
> thing.
>
> > But I'm not sure how your example of system("echo"...) applies to the
> > embedded blanks in a parameter issue.
> >
> > What I would like is for the user to be able to use one word, or two
> words,
> > or three words (or even more, I guess) for the 2nd parameter.  That is:
> > "Smith"   or "Mary Smith"   or "Mary Ann Smith".
> > And I would like all of these to be picked up as just the single
> parameter,
> > regardless of how many embedded spaces there are between the quotes.
> >
>
> If you do, for example:
>
> {{{
> system("ls", "-l", "Hello there/");
> }}}
>
> Then ls will display the files under the "Hello there" directory with a
> space
> in the path. You see - the list form of system treats each of the
> components
> of the list as a single command-line argument, even if it contains spaces.
>
> So this would be equivalent to doing the following commands in the shell:
>
> {{{
> ls -l "Hello there/"
> ls -l 'Hello there/'
> ls -l Hello\ there/
> }}}
>
> Regards,
>
>        Shlomi Fish
>
> > Thanks again for any help.
> > Regina
> >
> > --- In perl-beginner@yahoogroups.com, Shlomi Fish <shlomif@...> wrote:
> > > On Wednesday 17 June 2009 18:29:40 Regina Miller wrote:
> > > > Hi,
> > >
> > > Hi!
> > >
> > > First of all, you shouldn't use $ARGV[0] , $ARGV[1], etc. directly. Do:
> > >
> > > {{{
> > > my ($first_name, $last_name, $address) = @ARGV;
> > > }}}
> > >
> > > Which is a much more robust idea.
> > >
> > > Secondly, look at the list form of system:
> > >
> > > {{{
> > > system("echo", "One two", "three four--five");
> > > }}}
> > >
> > > Hope it helps.
> > >
> > > Regards,
> > >
> > >     Shlomi Fish
> > >
> > > > My script to add a new user is below, written on solaris 10.
> > > >
> > > >
> > > >
> > > > Running it using either of these two ways  (one with double quotes
> > > > around the second parameter and one with single quotes):
> > > >
> > > > ./adduser.sh TestAcct "John Smith" Law
> > > >
> > > > ./adduser.sh TestAcct 'John Smith' Law
> > > >
> > > > My script thinks I have entered four parameters.
> > > >
> > > >
> > > >
> > > > But when I run it using the following (with no embedded spaces):
> > > >
> > > > ./adduser.sh TestAcct JohnSmith Law
> > > >
> > > > It then thinks I have entered three parameters.
> > > >
> > > >
> > > >
> > > > How do I get a parameter that has embedded spaces to register as just
> > > > one parameter??
> > > >
> > > >
> > > >
> > > > Thanks for any help,
> > > >
> > > > Regina
> > > >
> > > >
> > > >
> > > > Regina Miller
> > > >
> > > > Lead Analyst, Grays Harbor County
> > > >
> > > > (360) 249-4144  ext  457
> > > >
> > > > rmiller@...
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > MY SCRIPT
> > > >
> > > >
> > > >
> > > > eval "exec ctperl -S $0 $*"
> > > >
> > > >     if $running_via_sh;
> > > >
> > > > #$Id: adduser.sh,v 302.4 1995/07/21 16:29:18 nick Exp $
> > > >
> > > > #require 'ctree.pl';
> > > >
> > > >
> #######################################################################
> > > ># ########
> > > >
> > > > # %perl
> > > >
> > > > # %width 80
> > > >
> > > > # %title Add a New User
> > > >
> > > > # %name adduser.sh
> > > >
> > > >
> > > >
> > > > use strict;
> > > >
> > > > use warnings;
> > > >
> > > >
> > > >
> > > > die 'Usage:  adduser username "full name" group.  i.e. adduser
> testacct
> > > > "John Smith" Law'
> > > >
> > > >    unless @ARGV == 3;
> > > >
> > > >
> > > >
> > > > unless (system "useradd -g $ARGV[2] -d /home/$ARGV[0] -m -s
> > > > /usr/bin/ksh -c $ARGV[1] $ARGV[0]")
> > > >
> > > > {
> > > >
> > > >    system "passwd $ARGV[0]";
> > > >
> > > >    exit;
> > > >
> > > > }
> > > >
> > > > print "Error.  User can not be added\n";
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > [Non-text portions of this message have been removed]
>
> --
> -----------------------------------------------------------------
> Shlomi Fish       http://www.shlomifish.org/
> Interview with Ben Collins-Sussman - http://xrl.us/bjn8s
>
> God gave us two eyes and ten fingers so we will type five times as much as
> we
> read.
>
>
> ------------------------------------
>
> Unsubscribing info is here:
> http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo! Groups Links
>
>
>
>


[Non-text portions of this message have been removed]

#26642 From: "Robert Lee Binkley" <leebinkley@...>
Date: Wed Jun 17, 2009 5:51 pm
Subject: RE: [PBML] #ARGV and parameters with embedded spaces.
leebinkley
Send Email Send Email
 
# cat add_smbuser

#!/sbin/sh



# This script must be invoked each time a new user

# is added to the UB-Domain (SAM), so he will find his home and

# a backup directory on our Samba-server.





OLDSAM=/etc/samba/oldsam.db

NEWSAM=/etc/samba/`isodate`sam.db

SMBBIN=/usr/local/samba/bin

HOMEDIR=/export/home/UB/

BUDIR=/export/userbackup/UB/

USERLIST=/tmp/newdomuser



# Get list of new users:



$SMBBIN/wbinfo -u > $NEWSAM

diff $OLDSAM $NEWSAM | grep '^>' | awk '{print $2}' | tr "[:upper:]"

"[:lower:]" > $USERLIST



# Create the user's directories:



if [ -s $USERLIST ]

then



   for i in `cat $USERLIST`; do

    mkdir $HOMEDIR$i $BUDIR$i

    chown $i:other $HOMEDIR$i $BUDIR$i

    chmod 700 $HOMEDIR$i $BUDIR$i

    echo Successfully created directories for $i

   done



   cp $NEWSAM $OLDSAM



else



   echo No new users in SAM



fi



rm $USERLIST







From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com]
On Behalf Of rmiller571957
Sent: Wednesday, June 17, 2009 11:38 AM
To: perl-beginner@yahoogroups.com
Subject: Re: [PBML] #ARGV and parameters with embedded spaces.








Thanks very much for the advice on not using $ARGV's directly.
I will change my code to match.

But I'm not sure how your example of system("echo"...) applies to the
embedded blanks in a parameter issue.

What I would like is for the user to be able to use one word, or two words,
or three words (or even more, I guess) for the 2nd parameter. That is:
"Smith" or "Mary Smith" or "Mary Ann Smith".
And I would like all of these to be picked up as just the single parameter,
regardless of how many embedded spaces there are between the quotes.

Thanks again for any help.
Regina

--- In perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com> , Shlomi Fish <shlomif@...> wrote:
>
> On Wednesday 17 June 2009 18:29:40 Regina Miller wrote:
> > Hi,
> >
>
> Hi!
>
> First of all, you shouldn't use $ARGV[0] , $ARGV[1], etc. directly. Do:
>
> {{{
> my ($first_name, $last_name, $address) = @ARGV;
> }}}
>
> Which is a much more robust idea.
>
> Secondly, look at the list form of system:
>
> {{{
> system("echo", "One two", "three four--five");
> }}}
>
> Hope it helps.
>
> Regards,
>
> Shlomi Fish
>
>
> >
> >
> > My script to add a new user is below, written on solaris 10.
> >
> >
> >
> > Running it using either of these two ways (one with double quotes
> > around the second parameter and one with single quotes):
> >
> > ./adduser.sh TestAcct "John Smith" Law
> >
> > ./adduser.sh TestAcct 'John Smith' Law
> >
> > My script thinks I have entered four parameters.
> >
> >
> >
> > But when I run it using the following (with no embedded spaces):
> >
> > ./adduser.sh TestAcct JohnSmith Law
> >
> > It then thinks I have entered three parameters.
> >
> >
> >
> > How do I get a parameter that has embedded spaces to register as just
> > one parameter??
> >
> >
> >
> > Thanks for any help,
> >
> > Regina
> >
> >
> >
> > Regina Miller
> >
> > Lead Analyst, Grays Harbor County
> >
> > (360) 249-4144 ext 457
> >
> > rmiller@...
> >
> >
> >
> >
> >
> > MY SCRIPT
> >
> >
> >
> > eval "exec ctperl -S $0 $*"
> >
> > if $running_via_sh;
> >
> > #$Id: adduser.sh,v 302.4 1995/07/21 16:29:18 nick Exp $
> >
> > #require 'ctree.pl';
> >
> > ########################################################################
> > ########
> >
> > # %perl
> >
> > # %width 80
> >
> > # %title Add a New User
> >
> > # %name adduser.sh
> >
> >
> >
> > use strict;
> >
> > use warnings;
> >
> >
> >
> > die 'Usage: adduser username "full name" group. i.e. adduser testacct
> > "John Smith" Law'
> >
> > unless @ARGV == 3;
> >
> >
> >
> > unless (system "useradd -g $ARGV[2] -d /home/$ARGV[0] -m -s /usr/bin/ksh
> > -c $ARGV[1] $ARGV[0]")
> >
> > {
> >
> > system "passwd $ARGV[0]";
> >
> > exit;
> >
> > }
> >
> > print "Error. User can not be added\n";
> >
> >
> >
> >
> >
> > [Non-text portions of this message have been removed]
>
> --
> ----------------------------------------------------------
> Shlomi Fish http://www.shlomifish.org/
> What does "Zionism" mean? - http://xrl.us/bjn8u
>
> God gave us two eyes and ten fingers so we will type five times as much as
we
> read.
>





[Non-text portions of this message have been removed]

#26643 From: "rmiller571957" <rmiller@...>
Date: Wed Jun 17, 2009 6:49 pm
Subject: Re: [PBML] #ARGV and parameters with embedded spaces.
rmiller571957
Send Email Send Email
 
This worked!  Thank you so much!

But now I'm having trouble passing my embedded-space-parameter on to the useradd
routine.  Here is my current code.  The problem is with the $username $ARGV[1]. 
The input "John Smith" is now correctly passed to my program as one parameter.

But how can I pass it on to the useradd command as one parameter?

Thanks again,
Regina
_______________________________________________________________
#!/sds/utilities/bin/perl
#require 'ctree.pl';
################################################################################
# %perl
# %width 80
# %title add a new user
# %name adduser.sh

use strict;
use warnings;

my $userid=$ARGV[0];
my $username=$ARGV[1];
my $usergroup=$ARGV[2];

die 'Usage:  adduser username "full name" group.  i.e. adduser testacct "John
Smith" Law' unless @ARGV == 3;

unless (system ("useradd -g $usergroup -d /home/$userid -m -s /usr/bin/ksh -c
$username $userid")) {
system "passwd $userid";
exit;
}
print "Error.  User can not be added\n";
______________________________________________________________






--- In perl-beginner@yahoogroups.com, Chris Seip <ssvfmnx@...> wrote:
>
> Hi Regina,
> The problem is caused by the eval shell statement:
>    eval "exec ctperl -S $0 $*"
>
> When the shell runs your shell script, the quotation marks have preserved
> the space in the "John Smith" command-line argument, but the quotation marks
> are stripped away by the time the script "sees" that argument.  So, that
> part of the $* argument list expands to John Smith (quoteless).  In the
> expansion it is a single command line argument, but you are leaving the
> space exposed on that eval exec... command line.  This splits the John Smith
> into two args for the ctperl script.
>
> Is the shell wrapper necessary around your ctperl script?
>
> Chris
>
>
>
> On Wed, Jun 17, 2009 at 9:48 AM, Shlomi Fish <shlomif@...> wrote:
>
> > On Wednesday 17 June 2009 19:38:04 rmiller571957 wrote:
> > > Thanks very much for the advice on not using $ARGV's directly.
> > > I will change my code to match.
> > >
> >
> > It's not $ARGV - it's @ARGV. @ARGV is the entire array. $ARGV[$index] is an
> > individual element of it. There's also $ARGV in Perl which is a different
> > thing.
> >
> > > But I'm not sure how your example of system("echo"...) applies to the
> > > embedded blanks in a parameter issue.
> > >
> > > What I would like is for the user to be able to use one word, or two
> > words,
> > > or three words (or even more, I guess) for the 2nd parameter.  That is:
> > > "Smith"   or "Mary Smith"   or "Mary Ann Smith".
> > > And I would like all of these to be picked up as just the single
> > parameter,
> > > regardless of how many embedded spaces there are between the quotes.
> > >
> >
> > If you do, for example:
> >
> > {{{
> > system("ls", "-l", "Hello there/");
> > }}}
> >
> > Then ls will display the files under the "Hello there" directory with a
> > space
> > in the path. You see - the list form of system treats each of the
> > components
> > of the list as a single command-line argument, even if it contains spaces.
> >
> > So this would be equivalent to doing the following commands in the shell:
> >
> > {{{
> > ls -l "Hello there/"
> > ls -l 'Hello there/'
> > ls -l Hello\ there/
> > }}}
> >
> > Regards,
> >
> >        Shlomi Fish
> >
> > > Thanks again for any help.
> > > Regina
> > >
> > > --- In perl-beginner@yahoogroups.com, Shlomi Fish <shlomif@> wrote:
> > > > On Wednesday 17 June 2009 18:29:40 Regina Miller wrote:
> > > > > Hi,
> > > >
> > > > Hi!
> > > >
> > > > First of all, you shouldn't use $ARGV[0] , $ARGV[1], etc. directly. Do:
> > > >
> > > > {{{
> > > > my ($first_name, $last_name, $address) = @ARGV;
> > > > }}}
> > > >
> > > > Which is a much more robust idea.
> > > >
> > > > Secondly, look at the list form of system:
> > > >
> > > > {{{
> > > > system("echo", "One two", "three four--five");
> > > > }}}
> > > >
> > > > Hope it helps.
> > > >
> > > > Regards,
> > > >
> > > >     Shlomi Fish
> > > >
> > > > > My script to add a new user is below, written on solaris 10.
> > > > >
> > > > >
> > > > >
> > > > > Running it using either of these two ways  (one with double quotes
> > > > > around the second parameter and one with single quotes):
> > > > >
> > > > > ./adduser.sh TestAcct "John Smith" Law
> > > > >
> > > > > ./adduser.sh TestAcct 'John Smith' Law
> > > > >
> > > > > My script thinks I have entered four parameters.
> > > > >
> > > > >
> > > > >
> > > > > But when I run it using the following (with no embedded spaces):
> > > > >
> > > > > ./adduser.sh TestAcct JohnSmith Law
> > > > >
> > > > > It then thinks I have entered three parameters.
> > > > >
> > > > >
> > > > >
> > > > > How do I get a parameter that has embedded spaces to register as just
> > > > > one parameter??
> > > > >
> > > > >
> > > > >
> > > > > Thanks for any help,
> > > > >
> > > > > Regina
> > > > >
> > > > >
> > > > >
> > > > > Regina Miller
> > > > >
> > > > > Lead Analyst, Grays Harbor County
> > > > >
> > > > > (360) 249-4144  ext  457
> > > > >
> > > > > rmiller@
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > MY SCRIPT
> > > > >
> > > > >
> > > > >
> > > > > eval "exec ctperl -S $0 $*"
> > > > >
> > > > >     if $running_via_sh;
> > > > >
> > > > > #$Id: adduser.sh,v 302.4 1995/07/21 16:29:18 nick Exp $
> > > > >
> > > > > #require 'ctree.pl';
> > > > >
> > > > >
> > #######################################################################
> > > > ># ########
> > > > >
> > > > > # %perl
> > > > >
> > > > > # %width 80
> > > > >
> > > > > # %title Add a New User
> > > > >
> > > > > # %name adduser.sh
> > > > >
> > > > >
> > > > >
> > > > > use strict;
> > > > >
> > > > > use warnings;
> > > > >
> > > > >
> > > > >
> > > > > die 'Usage:  adduser username "full name" group.  i.e. adduser
> > testacct
> > > > > "John Smith" Law'
> > > > >
> > > > >    unless @ARGV == 3;
> > > > >
> > > > >
> > > > >
> > > > > unless (system "useradd -g $ARGV[2] -d /home/$ARGV[0] -m -s
> > > > > /usr/bin/ksh -c $ARGV[1] $ARGV[0]")
> > > > >
> > > > > {
> > > > >
> > > > >    system "passwd $ARGV[0]";
> > > > >
> > > > >    exit;
> > > > >
> > > > > }
> > > > >
> > > > > print "Error.  User can not be added\n";
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > [Non-text portions of this message have been removed]
> >
> > --
> > -----------------------------------------------------------------
> > Shlomi Fish       http://www.shlomifish.org/
> > Interview with Ben Collins-Sussman - http://xrl.us/bjn8s
> >
> > God gave us two eyes and ten fingers so we will type five times as much as
> > we
> > read.
> >
> >
> > ------------------------------------
> >
> > Unsubscribing info is here:
> > http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo! Groups Links
> >
> >
> >
> >
>
>
> [Non-text portions of this message have been removed]
>

#26644 From: merlyn@...
Date: Wed Jun 17, 2009 6:56 pm
Subject: Re: [PBML] #ARGV and parameters with embedded spaces.
merlynstoneh...
Send Email Send Email
 
>>>>> "rmiller571957" == rmiller571957  <rmiller@...> writes:

rmiller571957> But how can I pass it on to the useradd command as one parameter?

As Shlomi Fish already showed you before... using a multi-arg system command:

rmiller571957> unless (system ("useradd -g $usergroup -d /home/$userid -m -s
/usr/bin/ksh -c $username $userid")) {

replace that with:

system "useradd","-g", $usergroup, "-d", "/home/$userid", "-m", "-s",
"/usr/bin/ksh", "-c", $username, $userid;

Please pay attention when people answer things for you.  We aren't just
making this stuff up. :)

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

#26645 From: "rmiller571957" <rmiller@...>
Date: Wed Jun 17, 2009 7:02 pm
Subject: Re: [PBML] #ARGV and parameters with embedded spaces.
rmiller571957
Send Email Send Email
 
Thank you!
And Shlomi, I'm sorry I didn't understand your response.  I played with it for
about 10 minutes, but just didn't see how it fit in with my situation.

My many thanks to all of you.  I believe I am on my way.

- Regina


--- In perl-beginner@yahoogroups.com, merlyn@... wrote:
>
> >>>>> "rmiller571957" == rmiller571957  <rmiller@...> writes:
>
> rmiller571957> But how can I pass it on to the useradd command as one
parameter?
>
> As Shlomi Fish already showed you before... using a multi-arg system command:
>
> rmiller571957> unless (system ("useradd -g $usergroup -d /home/$userid -m -s
/usr/bin/ksh -c $username $userid")) {
>
> replace that with:
>
> system "useradd","-g", $usergroup, "-d", "/home/$userid", "-m", "-s",
"/usr/bin/ksh", "-c", $username, $userid;
>
> Please pay attention when people answer things for you.  We aren't just
> making this stuff up. :)
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
> <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
> See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
>

#26646 From: "Kevin Patterson" <kpatters@...>
Date: Wed Jun 17, 2009 7:10 pm
Subject: Newbie question
cside30
Send Email Send Email
 
Hello..



I am writing a perl program in windows..



Here is my problem.



I have a file containing data such as:



Apples

Oranges

Pears

Bananas

Plums

Apples

Oranges

Pears

bananas

kiwi

Apples

Oranges

Pears

bananas





I write a program to read this file and  create a summary report showing

How many apples:

How many oranges

How many Pears



Can anyone help me??



thanks



[Non-text portions of this message have been removed]

#26647 From: merlyn@...
Date: Wed Jun 17, 2009 7:14 pm
Subject: Re: [PBML] Newbie question
merlynstoneh...
Send Email Send Email
 
>>>>> "Kevin" == Kevin Patterson <kpatters@...> writes:

Kevin> I write a program to read this file and  create a summary report showing

Kevin> How many apples:

Kevin> How many oranges

Kevin> How many Pears



Kevin> Can anyone help me??

What have you tried?  How far did you get?

If you don't have at least a working program to show, then you should
probably read some more first.

I would recommend the book "Learning Perl", for which by chapter 4 or so,
you'd be writing programs that do exactly that.  I'm a bit biased in that
recommendation of course. :)

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

#26648 From: "Scot Robnett" <scot@...>
Date: Wed Jun 17, 2009 7:21 pm
Subject: RE: [PBML] Newbie question
web4success2...
Send Email Send Email
 
What is the exact format of the file?

What have you tried so far?

Nobody is going to write the script for you. The group is here to help
you figure things out when you get stuck or something isn’t working, but
you’re supposed to try something first.



-----Original Message-----
From: perl-beginner@yahoogroups.com
[mailto:perl-beginner@yahoogroups.com] On Behalf Of Kevin Patterson
Sent: Wednesday, June 17, 2009 2:11 PM
To: perl-beginner@yahoogroups.com
Subject: [PBML] Newbie question





Hello..

I am writing a perl program in windows..

Here is my problem.

I have a file containing data such as:

Apples

Oranges

Pears

Bananas

Plums

Apples

Oranges

Pears

bananas

kiwi

Apples

Oranges

Pears

bananas

I write a program to read this file and create a summary report showing

How many apples:

How many oranges

How many Pears

Can anyone help me??

thanks

[Non-text portions of this message have been removed]

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.374 / Virus Database: 270.12.73/2180 - Release Date:
06/17/09 05:53:00

No virus found in this outgoing message.
Checked by AVG - www.avg.com
Version: 8.5.374 / Virus Database: 270.12.73/2180 - Release Date:
06/17/09 05:53:00



[Non-text portions of this message have been removed]

Messages 26613 - 26648 of 27459   Oldest  |  < Older  |  Newer >  |  Newest
Add to My Yahoo!      XML What's This?

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines NEW - Help