Search the web
Sign In
New User? Sign Up
perl-beginner · Perl Beginners Mailing List
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
#ARGV and parameters with embedded spaces.   Topic List   < Prev Topic  |  Next Topic >
Summarize Messages Sort by Date  
#26637 From: "Regina Miller" <rmiller@...>
Date: Wed Jun 17, 2009 3:29 pm
Subject: #ARGV and parameters with embedded spaces.
rmiller571957
Offline Offline
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
Offline Offline
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
Offline Offline
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
Offline Offline
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
Offline Offline
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]




#26643 From: "rmiller571957" <rmiller@...>
Date: Wed Jun 17, 2009 6:49 pm
Subject: Re: [PBML] #ARGV and parameters with embedded spaces.
rmiller571957
Offline Offline
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...
Online Now Online Now
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
Offline Offline
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
Offline Offline
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...
Online Now Online Now
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...
Offline Offline
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]




#26650 From: "Kevin Patterson" <kpatters@...>
Date: Wed Jun 17, 2009 8:17 pm
Subject: RE: [PBML] Newbie question
cside30
Offline Offline
Send Email Send Email
 
Sorry...

Here is what I wrote:

#!/usr/bin/perl

#use warnings;
#use diagnostics;

my $count = 0;
my $key_count = 0;
$Input_File="crapdata1.txt";
open(INP, $Input_File);
@by_jobname=<INP>;
close(INP);

foreach $New_Jobname (@by_jobname)
{
$em_job = substr($New_Jobname,11,50);
$em_key = substr($New_Jobname,11,2);

if ($em_key eq "Apples")
{
$count[1] = $count[1] + 1;
}

}

print "$em_key count is: $count[1]\n";

my $count = 0;
foreach $New_Jobname (@by_jobname)
{
$em_job = substr($New_Jobname,11,50);
$em_key = substr($New_Jobname,11,2);

if ($em_key eq "Oranges")
{
$count[2] = $count[2] + 1;
}

}
print "$em_key count is: $count[2]\n";
exit;




It give me the following results:

Apple Count is: 2
Oranges Count is: 1



Here is the data.

Apples |Sweet
Oranges |Seeds
Apples |Sour



-----Original Message-----
From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com]
On Behalf Of Scot Robnett
Sent: Wednesday, June 17, 2009 12:22 PM
To: perl-beginner@yahoogroups.com
Subject: RE: [PBML] Newbie question

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]



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

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







#26651 From: "Kevin Patterson" <kpatters@...>
Date: Wed Jun 17, 2009 8:39 pm
Subject: RE: [PBML] Newbie question
cside30
Offline Offline
Send Email Send Email
 
I fixed it.





#!/usr/bin/perl



#use warnings;

#use diagnostics;



my $count = 0;



@client = qw(apples oranges pears kiwi);



$Input_File="crapdata1.txt";

open(INP, $Input_File);

@by_jobname=<INP>;

close(INP);



foreach $Client_Key (@client)

{

foreach $New_Jobname (@by_jobname)

{

$em_job = substr($New_Jobname,11,50);

$em_key = substr($New_Jobname,11,2);



if ($em_key eq $Client_Key)

{

$count = $count + 1;

}



}

print "$Client_Key count is: $count\n";

$count = 0;

}





exit;



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








Sorry...

Here is what I wrote:

#!/usr/bin/perl

#use warnings;
#use diagnostics;

my $count = 0;
my $key_count = 0;
$Input_File="crapdata1.txt";
open(INP, $Input_File);
@by_jobname=<INP>;
close(INP);

foreach $New_Jobname (@by_jobname)
{
$em_job = substr($New_Jobname,11,50);
$em_key = substr($New_Jobname,11,2);

if ($em_key eq "Apples")
{
$count[1] = $count[1] + 1;
}

}

print "$em_key count is: $count[1]\n";

my $count = 0;
foreach $New_Jobname (@by_jobname)
{
$em_job = substr($New_Jobname,11,50);
$em_key = substr($New_Jobname,11,2);

if ($em_key eq "Oranges")
{
$count[2] = $count[2] + 1;
}

}
print "$em_key count is: $count[2]\n";
exit;

It give me the following results:

Apple Count is: 2
Oranges Count is: 1

Here is the data.

Apples |Sweet
Oranges |Seeds
Apples |Sour

-----Original Message-----
From: perl-beginner@yahoogroups.com <mailto:perl-beginner%40yahoogroups.com>
[mailto:perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com> ]
On Behalf Of Scot Robnett
Sent: Wednesday, June 17, 2009 12:22 PM
To: perl-beginner@yahoogroups.com <mailto:perl-beginner%40yahoogroups.com>
Subject: RE: [PBML] Newbie question

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%40yahoogroups.com>

[mailto:perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com> ] On Behalf Of Kevin Patterson
Sent: Wednesday, June 17, 2009 2:11 PM
To: perl-beginner@yahoogroups.com <mailto:perl-beginner%40yahoogroups.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]

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

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]




#26660 From: "Kevin Patterson" <kpatters@...>
Date: Wed Jun 24, 2009 1:33 am
Subject: Using System Command in Perl
cside30
Offline Offline
Send Email Send Email
 


Hi,



I am writing a perl program to call/ execute another windows program

Using the system command.



I am trying to get/print the results to see if the command worked.

Is there a way to capture the output of what the program ran??



I tried using system ' ' and system(). I get the same results.. nothing..



Here is my code so far.



#!/usr/bin/perl



# use strict;

# use warnings;





@client = qw(EM AS);



#@client = qw(EM HR KR AS BF DB);

my $eNV = "QW-D";

my $T = '"';



foreach $Client_Key (@client)

{



system 'CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y';



print "Status: $? $!\n";

}



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




#26661 From: Dan Stephenson <ispyhumanfly@...>
Date: Wed Jun 24, 2009 1:55 am
Subject: Re: [PBML] Using System Command in Perl
ispyhumanfly@...
Send Email Send Email
 
Kevin Patterson wrote:
>
>
>
>
> Hi,
>
> I am writing a perl program to call/ execute another windows program
>
> Using the system command.
>
> I am trying to get/print the results to see if the command worked.
>
> Is there a way to capture the output of what the program ran??
>
> I tried using system ' ' and system(). I get the same results.. nothing..
>
> Here is my code so far.
>
> #!/usr/bin/perl
>
> # use strict;
>
> # use warnings;
>
> @client = qw(EM AS);
>
> #@client = qw(EM HR KR AS BF DB);
>
> my $eNV = "QW-D";
>
> my $T = '"';
>
> foreach $Client_Key (@client)
>
> {
>
> system 'CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
> EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y';
>
> print "Status: $? $!\n";
>
> }
>
> [Non-text portions of this message have been removed]
>
>

Try opening the the command with a piped file handle, like so... the
below example will execute a given command and print the output to the
screen (you could very well parse this output and do stuff with the
information)...

open my $command, "command |";

while (my $line = <$command>) {

print $line; # you could do other stuff with this...
}

close $command;




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




#26662 From: Jeff Soules <soules@...>
Date: Wed Jun 24, 2009 4:57 pm
Subject: Re: [PBML] Using System Command in Perl
soules@...
Send Email Send Email
 
Maybe the backtick operator ` `?  (Backtick on my keyboard is the
tilde key ~ without shift, but it might be different on your
keyboard).

So in place of:

> system 'CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
> EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y';

You'd do

my $result = `CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y`;

and then look in $result for whatever the other utility would normally
print on the screen.

$? is supposed to be set the same way for system() as for the backtick
operator, but maybe your other Windows program isn't returning a
status properly or something?

On Tue, Jun 23, 2009 at 9:33 PM, Kevin Patterson<kpatters@...> wrote:
>
>
>
>
> Hi,
>
> I am writing a perl program to call/ execute another windows program
>
> Using the system command.
>
> I am trying to get/print the results to see if the command worked.
>
> Is there a way to capture the output of what the program ran??
>
> I tried using system ' ' and system(). I get the same results.. nothing..
>
> Here is my code so far.
>
> #!/usr/bin/perl
>
> # use strict;
>
> # use warnings;
>
> @client = qw(EM AS);
>
> #@client = qw(EM HR KR AS BF DB);
>
> my $eNV = "QW-D";
>
> my $T = '"';
>
> foreach $Client_Key (@client)
>
> {
>
> system 'CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
> EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y';
>
> print "Status: $? $!\n";
>
> }
>
> [Non-text portions of this message have been removed]
>
>



#26663 From: "Kevin Patterson" <kpatters@...>
Date: Wed Jun 24, 2009 5:09 pm
Subject: RE: [PBML] Using System Command in Perl
cside30
Offline Offline
Send Email Send Email
 
I TRIED IT THIS WAY.. INCLUDING WITH THE BACK LASHES. But I still get
nothing.. And I show nothing ran in task manager..



open my $command, "e:\BMC Software\CONTROL-M
Server\Ctm_server\Exe\CTMORDER.exe -SCHEDTAB EM-QW-D-REPORT-LOGS -JOBNAME
EM-QW-D-AS-AAL-EMAIL -ODATE ODAT -FORCE Y";



while (my $line = <$command>) {



print $line; # you could do other stuff with this...

}



close $command;



exit;



From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com]
On Behalf Of Jeff Soules
Sent: Wednesday, June 24, 2009 9:58 AM
To: perl-beginner@yahoogroups.com
Subject: Re: [PBML] Using System Command in Perl








Maybe the backtick operator ` `? (Backtick on my keyboard is the
tilde key ~ without shift, but it might be different on your
keyboard).

So in place of:

> system 'CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
> EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y';

You'd do

my $result = `CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y`;

and then look in $result for whatever the other utility would normally
print on the screen.

$? is supposed to be set the same way for system() as for the backtick
operator, but maybe your other Windows program isn't returning a
status properly or something?

On Tue, Jun 23, 2009 at 9:33 PM, Kevin Patterson<kpatters@...
<mailto:kpatters%40berkeley.edu> > wrote:
>
>
>
>
> Hi,
>
> I am writing a perl program to call/ execute another windows program
>
> Using the system command.
>
> I am trying to get/print the results to see if the command worked.
>
> Is there a way to capture the output of what the program ran??
>
> I tried using system ' ' and system(). I get the same results.. nothing..
>
> Here is my code so far.
>
> #!/usr/bin/perl
>
> # use strict;
>
> # use warnings;
>
> @client = qw(EM AS);
>
> #@client = qw(EM HR KR AS BF DB);
>
> my $eNV = "QW-D";
>
> my $T = '"';
>
> foreach $Client_Key (@client)
>
> {
>
> system 'CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
> EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y';
>
> print "Status: $? $!\n";
>
> }
>
> [Non-text portions of this message have been removed]
>
>





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




#26665 From: vishal thakur <lahsiv.vishal@...>
Date: Thu Jun 25, 2009 7:03 am
Subject: Re: [PBML] Using System Command in Perl
v_thakur123
Offline Offline
Send Email Send Email
 
When executing this command, don't forget to redirect the STDERR to STDIO,
else you won't be able to figure out the reason why command has failed, so i
will suggest following
my $result = `CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y 2>&1`;

so result will hold any output message or error message and to know the
status of the command just echo "$?"

On Wed, Jun 24, 2009 at 10:27 PM, Jeff Soules <soules@...> wrote:

>
>
> Maybe the backtick operator ` `? (Backtick on my keyboard is the
> tilde key ~ without shift, but it might be different on your
> keyboard).
>
> So in place of:
>
>
> > system 'CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
> > EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y';
>
> You'd do
>
> my $result = `CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
> EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y`;
>
> and then look in $result for whatever the other utility would normally
> print on the screen.
>
> $? is supposed to be set the same way for system() as for the backtick
> operator, but maybe your other Windows program isn't returning a
> status properly or something?
>
> On Tue, Jun 23, 2009 at 9:33 PM, Kevin
Patterson<kpatters@...<kpatters%40berkeley.edu>>
> wrote:
> >
> >
> >
> >
> > Hi,
> >
> > I am writing a perl program to call/ execute another windows program
> >
> > Using the system command.
> >
> > I am trying to get/print the results to see if the command worked.
> >
> > Is there a way to capture the output of what the program ran??
> >
> > I tried using system ' ' and system(). I get the same results.. nothing..
> >
> > Here is my code so far.
> >
> > #!/usr/bin/perl
> >
> > # use strict;
> >
> > # use warnings;
> >
> > @client = qw(EM AS);
> >
> > #@client = qw(EM HR KR AS BF DB);
> >
> > my $eNV = "QW-D";
> >
> > my $T = '"';
> >
> > foreach $Client_Key (@client)
> >
> > {
> >
> > system 'CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
> > EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y';
> >
> > print "Status: $? $!\n";
> >
> > }
> >
> > [Non-text portions of this message have been removed]
> >
> >
>
>



--
Regards
Vishal Thakur
+919923206953


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




#26666 From: Shlomi Fish <shlomif@...>
Date: Thu Jun 25, 2009 9:36 am
Subject: Re: [PBML] Using System Command in Perl
shlomif2
Offline Offline
Send Email Send Email
 
On Wednesday 24 June 2009 19:57:50 Jeff Soules wrote:
> Maybe the backtick operator ` `? (Backtick on my keyboard is the
> tilde key ~ without shift, but it might be different on your
> keyboard).
>
> So in place of:
> > system 'CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
> > EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y';
>
> You'd do
>
> my $result = `CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
> EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y`;
>

In that case, make sure you use String-ShellQuote:

http://search.cpan.org/dist/String-ShellQuote/

Alternatively use open '-|', @list which is only available on Windows.

Regards,

Shlomi Fish

> and then look in $result for whatever the other utility would normally
> print on the screen.
>
> $? is supposed to be set the same way for system() as for the backtick
> operator, but maybe your other Windows program isn't returning a
> status properly or something?
>
> On Tue, Jun 23, 2009 at 9:33 PM, Kevin Patterson<kpatters@...>
wrote:
> > Hi,
> >
> > I am writing a perl program to call/ execute another windows program
> >
> > Using the system command.
> >
> > I am trying to get/print the results to see if the command worked.
> >
> > Is there a way to capture the output of what the program ran??
> >
> > I tried using system ' ' and system(). I get the same results.. nothing..
> >
> > Here is my code so far.
> >
> > #!/usr/bin/perl
> >
> > # use strict;
> >
> > # use warnings;
> >
> > @client = qw(EM AS);
> >
> > #@client = qw(EM HR KR AS BF DB);
> >
> > my $eNV = "QW-D";
> >
> > my $T = '"';
> >
> > foreach $Client_Key (@client)
> >
> > {
> >
> > system 'CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
> > EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y';
> >
> > print "Status: $? $!\n";
> >
> > }
> >
> > [Non-text portions of this message have been removed]

--
-----------------------------------------------------------------
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.



#26652 From: Jeff Soules <soules@...>
Date: Wed Jun 17, 2009 8:45 pm
Subject: Re: [PBML] Newbie question
soules@...
Send Email Send Email
 
You've had prior experience with other programming languages, right?
Using substr() this way is a very C or Java way of doing things.

Read up on hashes ("associative arrays") and the split() function in Perl.

http://www.tutorialspoint.com/perl/perl_hashes.htm is just one of many
possible tutorials about hashes.
http://www.perlmeme.org/howtos/perlfunc/split_function.html seems a
decent enough split() tutorial.
I don't claim anything about the quality of these tutorials (I haven't
actually read them), they just came from the first page of google
results.

The idea of a hash is that it's like an array, but you can access the
individual variables by a text-based key, instead of by a numeric
index. So, instead of having to cycle through your list once for
apples, once for oranges, once for pears, etc., and then re-write your
code when your, err, user decides that the program should also work
for tangerines, instead you can use a hash where the fruit name is the
key and the count is the value. So you could access your hash as
$fruitCount{'Apples'} += 1, say. Or even better,
$fruitCount{$fruitName} += 1;
Doing the latter, you could build the entire hash table without ever
needing to know the types of fruit in advance; and you would
automatically cover every type of fruit mentioned in the input file.
The only question would be, "hey, how do I get the fruit name?"
Well...

With the split() function, you can divide your input lines logically,
instead of by using substr() and hoping that all fruits have the same
number of characters. split() lets you break a string apart according
to a delimiter character. In the case of your example here, you have
the name of a fruit, followed by a pipe |. So that | would be the
delimiting character; what you really want is the fruit name that
comes in front of it. If you split each line along the |, then you
can store the first chunk as the fruit name, and throw away the second
part (since, at least so far, you don't really care what the rest of
the line says).

Once you've built up your hash, you'll want to dump its contents. For
this, you'll need the keys() function, which you'll no doubt find
plenty of information about online.

One of the Perl mottoes is "There's More Than One Way to Do It"
(TMTOWDI) and the solution I'm hinting you at here is just one of many
possible ones (that's what makes Perl fun!) But hopefully this will
set you on the way to finding one of the many solutions.

Do check back!


On Wed, Jun 17, 2009 at 4:17 PM, Kevin Patterson<kpatters@...> wrote:
>
>
> Sorry...
>
> Here is what I wrote:
>
> #!/usr/bin/perl
>
> #use warnings;
> #use diagnostics;
>
> my $count = 0;
> my $key_count = 0;
> $Input_File="crapdata1.txt";
> open(INP, $Input_File);
> @by_jobname=<INP>;
> close(INP);
>
> foreach $New_Jobname (@by_jobname)
> {
> $em_job = substr($New_Jobname,11,50);
> $em_key = substr($New_Jobname,11,2);
>
> if ($em_key eq "Apples")
> {
> $count[1] = $count[1] + 1;
> }
>
> }
>
> print "$em_key count is: $count[1]\n";
>
> my $count = 0;
> foreach $New_Jobname (@by_jobname)
> {
> $em_job = substr($New_Jobname,11,50);
> $em_key = substr($New_Jobname,11,2);
>
> if ($em_key eq "Oranges")
> {
> $count[2] = $count[2] + 1;
> }
>
> }
> print "$em_key count is: $count[2]\n";
> exit;
>
> It give me the following results:
>
> Apple Count is: 2
> Oranges Count is: 1
>
> Here is the data.
>
> Apples |Sweet
> Oranges |Seeds
> Apples |Sour
>
> -----Original Message-----
> From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com]
> On Behalf Of Scot Robnett
> Sent: Wednesday, June 17, 2009 12:22 PM
> To: perl-beginner@yahoogroups.com
> Subject: RE: [PBML] Newbie question
>
> 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]
>
> ------------------------------------
>
> Unsubscribing info is here:
> http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo! Groups Links
>
>



#26653 From: "Kevin Patterson" <kpatters@...>
Date: Wed Jun 17, 2009 8:50 pm
Subject: RE: [PBML] Newbie question
cside30
Offline Offline
Send Email Send Email
 
Thanks.



I am reading on hashes now and practicing on how to use them. I have not
taken any perl classes..



I just started reading the books.



From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com]
On Behalf Of Jeff Soules
Sent: Wednesday, June 17, 2009 1:46 PM
To: perl-beginner@yahoogroups.com
Subject: Re: [PBML] Newbie question








You've had prior experience with other programming languages, right?
Using substr() this way is a very C or Java way of doing things.

Read up on hashes ("associative arrays") and the split() function in Perl.

http://www.tutorialspoint.com/perl/perl_hashes.htm is just one of many
possible tutorials about hashes.
http://www.perlmeme.org/howtos/perlfunc/split_function.html seems a
decent enough split() tutorial.
I don't claim anything about the quality of these tutorials (I haven't
actually read them), they just came from the first page of google
results.

The idea of a hash is that it's like an array, but you can access the
individual variables by a text-based key, instead of by a numeric
index. So, instead of having to cycle through your list once for
apples, once for oranges, once for pears, etc., and then re-write your
code when your, err, user decides that the program should also work
for tangerines, instead you can use a hash where the fruit name is the
key and the count is the value. So you could access your hash as
$fruitCount{'Apples'} += 1, say. Or even better,
$fruitCount{$fruitName} += 1;
Doing the latter, you could build the entire hash table without ever
needing to know the types of fruit in advance; and you would
automatically cover every type of fruit mentioned in the input file.
The only question would be, "hey, how do I get the fruit name?"
Well...

With the split() function, you can divide your input lines logically,
instead of by using substr() and hoping that all fruits have the same
number of characters. split() lets you break a string apart according
to a delimiter character. In the case of your example here, you have
the name of a fruit, followed by a pipe |. So that | would be the
delimiting character; what you really want is the fruit name that
comes in front of it. If you split each line along the |, then you
can store the first chunk as the fruit name, and throw away the second
part (since, at least so far, you don't really care what the rest of
the line says).

Once you've built up your hash, you'll want to dump its contents. For
this, you'll need the keys() function, which you'll no doubt find
plenty of information about online.

One of the Perl mottoes is "There's More Than One Way to Do It"
(TMTOWDI) and the solution I'm hinting you at here is just one of many
possible ones (that's what makes Perl fun!) But hopefully this will
set you on the way to finding one of the many solutions.

Do check back!

On Wed, Jun 17, 2009 at 4:17 PM, Kevin Patterson<kpatters@...
<mailto:kpatters%40berkeley.edu> > wrote:
>
>
> Sorry...
>
> Here is what I wrote:
>
> #!/usr/bin/perl
>
> #use warnings;
> #use diagnostics;
>
> my $count = 0;
> my $key_count = 0;
> $Input_File="crapdata1.txt";
> open(INP, $Input_File);
> @by_jobname=<INP>;
> close(INP);
>
> foreach $New_Jobname (@by_jobname)
> {
> $em_job = substr($New_Jobname,11,50);
> $em_key = substr($New_Jobname,11,2);
>
> if ($em_key eq "Apples")
> {
> $count[1] = $count[1] + 1;
> }
>
> }
>
> print "$em_key count is: $count[1]\n";
>
> my $count = 0;
> foreach $New_Jobname (@by_jobname)
> {
> $em_job = substr($New_Jobname,11,50);
> $em_key = substr($New_Jobname,11,2);
>
> if ($em_key eq "Oranges")
> {
> $count[2] = $count[2] + 1;
> }
>
> }
> print "$em_key count is: $count[2]\n";
> exit;
>
> It give me the following results:
>
> Apple Count is: 2
> Oranges Count is: 1
>
> Here is the data.
>
> Apples |Sweet
> Oranges |Seeds
> Apples |Sour
>
> -----Original Message-----
> From: perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com>
[mailto:perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com> ]
> On Behalf Of Scot Robnett
> Sent: Wednesday, June 17, 2009 12:22 PM
> To: perl-beginner@yahoogroups.com <mailto:perl-beginner%40yahoogroups.com>

> Subject: RE: [PBML] Newbie question
>
> 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%40yahoogroups.com>
> [mailto:perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com> ] On Behalf Of Kevin Patterson
> Sent: Wednesday, June 17, 2009 2:11 PM
> To: perl-beginner@yahoogroups.com <mailto:perl-beginner%40yahoogroups.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]
>
> ------------------------------------
>
> 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]




#26654 From: Jeff Soules <soules@...>
Date: Wed Jun 17, 2009 8:53 pm
Subject: Re: [PBML] Newbie question
soules@...
Send Email Send Email
 
> I am reading on hashes now and practicing on how to use them. I have not
> taken any perl classes..
>
> I just started reading the books.

If you're learning from books, I cannot recommend _Learning_Perl_
highly enough. It's got a very intelligent presentation order, tons
of useful example exercises, and even an engaging body text.

Good luck.

On Wed, Jun 17, 2009 at 4:50 PM, Kevin Patterson<kpatters@...> wrote:
>
>
> Thanks.
>
> I am reading on hashes now and practicing on how to use them. I have not
> taken any perl classes..
>
> I just started reading the books.
>
> From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com]
> On Behalf Of Jeff Soules
> Sent: Wednesday, June 17, 2009 1:46 PM
> To: perl-beginner@yahoogroups.com
> Subject: Re: [PBML] Newbie question
>
> You've had prior experience with other programming languages, right?
> Using substr() this way is a very C or Java way of doing things.
>
> Read up on hashes ("associative arrays") and the split() function in Perl.
>
> http://www.tutorialspoint.com/perl/perl_hashes.htm is just one of many
> possible tutorials about hashes.
> http://www.perlmeme.org/howtos/perlfunc/split_function.html seems a
> decent enough split() tutorial.
> I don't claim anything about the quality of these tutorials (I haven't
> actually read them), they just came from the first page of google
> results.
>
> The idea of a hash is that it's like an array, but you can access the
> individual variables by a text-based key, instead of by a numeric
> index. So, instead of having to cycle through your list once for
> apples, once for oranges, once for pears, etc., and then re-write your
> code when your, err, user decides that the program should also work
> for tangerines, instead you can use a hash where the fruit name is the
> key and the count is the value. So you could access your hash as
> $fruitCount{'Apples'} += 1, say. Or even better,
> $fruitCount{$fruitName} += 1;
> Doing the latter, you could build the entire hash table without ever
> needing to know the types of fruit in advance; and you would
> automatically cover every type of fruit mentioned in the input file.
> The only question would be, "hey, how do I get the fruit name?"
> Well...
>
> With the split() function, you can divide your input lines logically,
> instead of by using substr() and hoping that all fruits have the same
> number of characters. split() lets you break a string apart according
> to a delimiter character. In the case of your example here, you have
> the name of a fruit, followed by a pipe |. So that | would be the
> delimiting character; what you really want is the fruit name that
> comes in front of it. If you split each line along the |, then you
> can store the first chunk as the fruit name, and throw away the second
> part (since, at least so far, you don't really care what the rest of
> the line says).
>
> Once you've built up your hash, you'll want to dump its contents. For
> this, you'll need the keys() function, which you'll no doubt find
> plenty of information about online.
>
> One of the Perl mottoes is "There's More Than One Way to Do It"
> (TMTOWDI) and the solution I'm hinting you at here is just one of many
> possible ones (that's what makes Perl fun!) But hopefully this will
> set you on the way to finding one of the many solutions.
>
> Do check back!
>
> On Wed, Jun 17, 2009 at 4:17 PM, Kevin Patterson<kpatters@...
> <mailto:kpatters%40berkeley.edu> > wrote:
>>
>>
>> Sorry...
>>
>> Here is what I wrote:
>>
>> #!/usr/bin/perl
>>
>> #use warnings;
>> #use diagnostics;
>>
>> my $count = 0;
>> my $key_count = 0;
>> $Input_File="crapdata1.txt";
>> open(INP, $Input_File);
>> @by_jobname=<INP>;
>> close(INP);
>>
>> foreach $New_Jobname (@by_jobname)
>> {
>> $em_job = substr($New_Jobname,11,50);
>> $em_key = substr($New_Jobname,11,2);
>>
>> if ($em_key eq "Apples")
>> {
>> $count[1] = $count[1] + 1;
>> }
>>
>> }
>>
>> print "$em_key count is: $count[1]\n";
>>
>> my $count = 0;
>> foreach $New_Jobname (@by_jobname)
>> {
>> $em_job = substr($New_Jobname,11,50);
>> $em_key = substr($New_Jobname,11,2);
>>
>> if ($em_key eq "Oranges")
>> {
>> $count[2] = $count[2] + 1;
>> }
>>
>> }
>> print "$em_key count is: $count[2]\n";
>> exit;
>>
>> It give me the following results:
>>
>> Apple Count is: 2
>> Oranges Count is: 1
>>
>> Here is the data.
>>
>> Apples |Sweet
>> Oranges |Seeds
>> Apples |Sour
>>
>> -----Original Message-----
>> From: perl-beginner@yahoogroups.com
> <mailto:perl-beginner%40yahoogroups.com>
> [mailto:perl-beginner@yahoogroups.com
> <mailto:perl-beginner%40yahoogroups.com> ]
>> On Behalf Of Scot Robnett
>> Sent: Wednesday, June 17, 2009 12:22 PM
>> To: perl-beginner@yahoogroups.com <mailto:perl-beginner%40yahoogroups.com>
>
>> Subject: RE: [PBML] Newbie question
>>
>> 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%40yahoogroups.com>
>> [mailto:perl-beginner@yahoogroups.com
> <mailto:perl-beginner%40yahoogroups.com> ] On Behalf Of Kevin Patterson
>> Sent: Wednesday, June 17, 2009 2:11 PM
>> To: perl-beginner@yahoogroups.com <mailto:perl-beginner%40yahoogroups.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]
>>
>> ------------------------------------
>>
>> 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]
>
>



#26655 From: "Kevin Patterson" <kpatters@...>
Date: Wed Jun 17, 2009 8:55 pm
Subject: RE: [PBML] Newbie question
cside30
Offline Offline
Send Email Send Email
 
Thanks.



I have it on order and reading it online now..



From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com]
On Behalf Of Jeff Soules
Sent: Wednesday, June 17, 2009 1:53 PM
To: perl-beginner@yahoogroups.com
Subject: Re: [PBML] Newbie question








> I am reading on hashes now and practicing on how to use them. I have not
> taken any perl classes..
>
> I just started reading the books.

If you're learning from books, I cannot recommend _Learning_Perl_
highly enough. It's got a very intelligent presentation order, tons
of useful example exercises, and even an engaging body text.

Good luck.

On Wed, Jun 17, 2009 at 4:50 PM, Kevin Patterson<kpatters@...
<mailto:kpatters%40berkeley.edu> > wrote:
>
>
> Thanks.
>
> I am reading on hashes now and practicing on how to use them. I have not
> taken any perl classes..
>
> I just started reading the books.
>
> From: perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com>
[mailto:perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com> ]
> On Behalf Of Jeff Soules
> Sent: Wednesday, June 17, 2009 1:46 PM
> To: perl-beginner@yahoogroups.com <mailto:perl-beginner%40yahoogroups.com>

> Subject: Re: [PBML] Newbie question
>
> You've had prior experience with other programming languages, right?
> Using substr() this way is a very C or Java way of doing things.
>
> Read up on hashes ("associative arrays") and the split() function in Perl.
>
> http://www.tutorialspoint.com/perl/perl_hashes.htm is just one of many
> possible tutorials about hashes.
> http://www.perlmeme.org/howtos/perlfunc/split_function.html seems a
> decent enough split() tutorial.
> I don't claim anything about the quality of these tutorials (I haven't
> actually read them), they just came from the first page of google
> results.
>
> The idea of a hash is that it's like an array, but you can access the
> individual variables by a text-based key, instead of by a numeric
> index. So, instead of having to cycle through your list once for
> apples, once for oranges, once for pears, etc., and then re-write your
> code when your, err, user decides that the program should also work
> for tangerines, instead you can use a hash where the fruit name is the
> key and the count is the value. So you could access your hash as
> $fruitCount{'Apples'} += 1, say. Or even better,
> $fruitCount{$fruitName} += 1;
> Doing the latter, you could build the entire hash table without ever
> needing to know the types of fruit in advance; and you would
> automatically cover every type of fruit mentioned in the input file.
> The only question would be, "hey, how do I get the fruit name?"
> Well...
>
> With the split() function, you can divide your input lines logically,
> instead of by using substr() and hoping that all fruits have the same
> number of characters. split() lets you break a string apart according
> to a delimiter character. In the case of your example here, you have
> the name of a fruit, followed by a pipe |. So that | would be the
> delimiting character; what you really want is the fruit name that
> comes in front of it. If you split each line along the |, then you
> can store the first chunk as the fruit name, and throw away the second
> part (since, at least so far, you don't really care what the rest of
> the line says).
>
> Once you've built up your hash, you'll want to dump its contents. For
> this, you'll need the keys() function, which you'll no doubt find
> plenty of information about online.
>
> One of the Perl mottoes is "There's More Than One Way to Do It"
> (TMTOWDI) and the solution I'm hinting you at here is just one of many
> possible ones (that's what makes Perl fun!) But hopefully this will
> set you on the way to finding one of the many solutions.
>
> Do check back!
>
> On Wed, Jun 17, 2009 at 4:17 PM, Kevin Patterson<kpatters@...
<mailto:kpatters%40berkeley.edu>
> <mailto:kpatters%40berkeley.edu> > wrote:
>>
>>
>> Sorry...
>>
>> Here is what I wrote:
>>
>> #!/usr/bin/perl
>>
>> #use warnings;
>> #use diagnostics;
>>
>> my $count = 0;
>> my $key_count = 0;
>> $Input_File="crapdata1.txt";
>> open(INP, $Input_File);
>> @by_jobname=<INP>;
>> close(INP);
>>
>> foreach $New_Jobname (@by_jobname)
>> {
>> $em_job = substr($New_Jobname,11,50);
>> $em_key = substr($New_Jobname,11,2);
>>
>> if ($em_key eq "Apples")
>> {
>> $count[1] = $count[1] + 1;
>> }
>>
>> }
>>
>> print "$em_key count is: $count[1]\n";
>>
>> my $count = 0;
>> foreach $New_Jobname (@by_jobname)
>> {
>> $em_job = substr($New_Jobname,11,50);
>> $em_key = substr($New_Jobname,11,2);
>>
>> if ($em_key eq "Oranges")
>> {
>> $count[2] = $count[2] + 1;
>> }
>>
>> }
>> print "$em_key count is: $count[2]\n";
>> exit;
>>
>> It give me the following results:
>>
>> Apple Count is: 2
>> Oranges Count is: 1
>>
>> Here is the data.
>>
>> Apples |Sweet
>> Oranges |Seeds
>> Apples |Sour
>>
>> -----Original Message-----
>> From: perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
> [mailto:perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com> ]
>> On Behalf Of Scot Robnett
>> Sent: Wednesday, June 17, 2009 12:22 PM
>> To: perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com>
<mailto:perl-beginner%40yahoogroups.com>
>
>> Subject: RE: [PBML] Newbie question
>>
>> 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%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
>> [mailto:perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com> ] On Behalf Of Kevin Patterson
>> Sent: Wednesday, June 17, 2009 2:11 PM
>> To: perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com>
<mailto:perl-beginner%40yahoogroups.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]
>>
>> ------------------------------------
>>
>> 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]
>
>





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




#26656 From: "Kevin Patterson" <kpatters@...>
Date: Wed Jun 17, 2009 10:07 pm
Subject: RE: [PBML] Newbie question
cside30
Offline Offline
Send Email Send Email
 
Ok.



Im stuck again.



I need to sort this input file below before my code..

Cant someone help me with this??



>> #!/usr/bin/perl
>>
>> #use warnings;
>> #use diagnostics;
>>
>> my $count = 0;
>> my $key_count = 0;
>> $Input_File="crapdata1.txt";
>> open(INP, $Input_File);
>> @by_jobname=<INP>;
>> close(INP);
>>
>> foreach $New_Jobname (@by_jobname)
>> {
>> $em_job = substr($New_Jobname,11,50);
>> $em_key = substr($New_Jobname,11,2);
>>
>> if ($em_key eq "Apples")
>> {
>> $count[1] = $count[1] + 1;
>> }
>>
>> }
>>
>> print "$em_key count is: $count[1]\n";
>>
>> my $count = 0;
>> foreach $New_Jobname (@by_jobname)
>> {
>> $em_job = substr($New_Jobname,11,50);
>> $em_key = substr($New_Jobname,11,2);
>>
>> if ($em_key eq "Oranges")
>> {
>> $count[2] = $count[2] + 1;
>> }
>>
>> }
>> print "$em_key count is: $count[2]\n";
>> exit;
>>
>> It give me the following results:
>>
>> Apple Count is: 2
>> Oranges Count is: 1
>>
>> Here is the data.
>>
>> Apples |Sweet
>> Oranges |Seeds
>> Apples |Sour
>>
>> -----Original Message-----
>> From: perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com>
<mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
> [mailto:perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com>
<mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com> ]
>> On Behalf Of Scot Robnett
>> Sent: Wednesday, June 17, 2009 12:22 PM
>> To: perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com>
<mailto:perl-beginner%40yahoogroups.com>
<mailto:perl-beginner%40yahoogroups.com>
>
>> Subject: RE: [PBML] Newbie question
>>
>> 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%40yahoogroups.com>
<mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
>> [mailto:perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com>
<mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com> ] On Behalf Of Kevin Patterson
>> Sent: Wednesday, June 17, 2009 2:11 PM
>> To: perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com>
<mailto:perl-beginner%40yahoogroups.com>
<mailto:perl-beginner%40yahoogroups.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]
>>
>> ------------------------------------
>>
>> 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]
>
>

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





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




#26658 From: Jeff Soules <soules@...>
Date: Thu Jun 18, 2009 12:22 pm
Subject: Re: [PBML] Newbie question
soules@...
Send Email Send Email
 
In a Unix environment, the easiest way to sort the file would be to
use the sort utility on the file. But you said you're running in
Windows. So, since your code was loading the entire file into an
array (one line per array element) before processing it, you could
then sort that array using Perl's sort() function. This would put the
lines in alphabetical order.

However, per the problem description that you've posted and the
hash-based solution which people have pointed you towards, the line
order in the file shouldn't be a problem. Has your problem situation
changed?

On Wed, Jun 17, 2009 at 6:07 PM, Kevin Patterson<kpatters@...> wrote:
>
>
> Ok.
>
> Im stuck again.
>
> I need to sort this input file below before my code..
>
> Cant someone help me with this??
>
>>> #!/usr/bin/perl
>>>
>>> #use warnings;
>>> #use diagnostics;
>>>
>>> my $count = 0;
>>> my $key_count = 0;
>>> $Input_File="crapdata1.txt";
>>> open(INP, $Input_File);
>>> @by_jobname=<INP>;
>>> close(INP);
>>>
>>> foreach $New_Jobname (@by_jobname)
>>> {
>>> $em_job = substr($New_Jobname,11,50);
>>> $em_key = substr($New_Jobname,11,2);
>>>
>>> if ($em_key eq "Apples")
>>> {
>>> $count[1] = $count[1] + 1;
>>> }
>>>
>>> }
>>>
>>> print "$em_key count is: $count[1]\n";
>>>
>>> my $count = 0;
>>> foreach $New_Jobname (@by_jobname)
>>> {
>>> $em_job = substr($New_Jobname,11,50);
>>> $em_key = substr($New_Jobname,11,2);
>>>
>>> if ($em_key eq "Oranges")
>>> {
>>> $count[2] = $count[2] + 1;
>>> }
>>>
>>> }
>>> print "$em_key count is: $count[2]\n";
>>> exit;
>>>
>>> It give me the following results:
>>>
>>> Apple Count is: 2
>>> Oranges Count is: 1
>>>
>>> Here is the data.
>>>
>>> Apples |Sweet
>>> Oranges |Seeds
>>> Apples |Sour
>>>
>>> -----Original Message-----
>>> From: perl-beginner@yahoogroups.com
> <mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
>> <mailto:perl-beginner%40yahoogroups.com>
>> [mailto:perl-beginner@yahoogroups.com
> <mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
>> <mailto:perl-beginner%40yahoogroups.com> ]
>>> On Behalf Of Scot Robnett
>>> Sent: Wednesday, June 17, 2009 12:22 PM
>>> To: perl-beginner@yahoogroups.com
> <mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
>>
>>> Subject: RE: [PBML] Newbie question
>>>
>>> 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%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
>> <mailto:perl-beginner%40yahoogroups.com>
>>> [mailto:perl-beginner@yahoogroups.com
> <mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
>> <mailto:perl-beginner%40yahoogroups.com> ] On Behalf Of Kevin Patterson
>>> Sent: Wednesday, June 17, 2009 2:11 PM
>>> To: perl-beginner@yahoogroups.com
> <mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.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]
>>>
>>> ------------------------------------
>>>
>>> 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]
>>
>>
>
> [Non-text portions of this message have been removed]
>
> [Non-text portions of this message have been removed]
>
>



#26659 From: "Robert Lee Binkley" <leebinkley@...>
Date: Fri Jun 19, 2009 4:38 am
Subject: RE: [PBML] Newbie question
leebinkley
Offline Offline
Send Email Send Email
 
Hope this helps



Output:

Apples count is: 3
Oranges count is: 3
Pears count is: 3



Src:

#!/usr/bin/perl



use strict;
use warnings;
my $count = 0;
my $key_count = 0;



my %MFN = qw(apples 0 oranges 0 pears 0);
my $MyFruitNames = \%MFN;



INPUTTP: while ( <DATA> ) {
chomp;
last if ( /^\s*_{1,2}\s*end\d{0,}\s*_{1,}/ );

s/^\s+//g;
$_ = lc($_);
$MyFruitNames->{$_}++ if ( defined $MyFruitNames->{$_} );
}
my $MyPrtKey;
foreach $MyPrtKey ( sort keys %{$MyFruitNames} ) {
printf "%s count is: %3d\n",
ucfirst($MyPrtKey),
$MyFruitNames->{$MyPrtKey};
}
__DATA__
Apples
Oranges
Pears
Bananas
Plums
Apples
Oranges
Pears
bananas
kiwi
Apples
Oranges
Pears
bananas
__END0__





From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com]
On Behalf Of Jeff Soules
Sent: Thursday, June 18, 2009 7:22 AM
To: perl-beginner@yahoogroups.com
Subject: Re: [PBML] Newbie question








In a Unix environment, the easiest way to sort the file would be to
use the sort utility on the file. But you said you're running in
Windows. So, since your code was loading the entire file into an
array (one line per array element) before processing it, you could
then sort that array using Perl's sort() function. This would put the
lines in alphabetical order.

However, per the problem description that you've posted and the
hash-based solution which people have pointed you towards, the line
order in the file shouldn't be a problem. Has your problem situation
changed?

On Wed, Jun 17, 2009 at 6:07 PM, Kevin Patterson<kpatters@...
<mailto:kpatters%40berkeley.edu> > wrote:
>
>
> Ok.
>
> Im stuck again.
>
> I need to sort this input file below before my code..
>
> Cant someone help me with this??
>
>>> #!/usr/bin/perl
>>>
>>> #use warnings;
>>> #use diagnostics;
>>>
>>> my $count = 0;
>>> my $key_count = 0;
>>> $Input_File="crapdata1.txt";
>>> open(INP, $Input_File);
>>> @by_jobname=<INP>;
>>> close(INP);
>>>
>>> foreach $New_Jobname (@by_jobname)
>>> {
>>> $em_job = substr($New_Jobname,11,50);
>>> $em_key = substr($New_Jobname,11,2);
>>>
>>> if ($em_key eq "Apples")
>>> {
>>> $count[1] = $count[1] + 1;
>>> }
>>>
>>> }
>>>
>>> print "$em_key count is: $count[1]\n";
>>>
>>> my $count = 0;
>>> foreach $New_Jobname (@by_jobname)
>>> {
>>> $em_job = substr($New_Jobname,11,50);
>>> $em_key = substr($New_Jobname,11,2);
>>>
>>> if ($em_key eq "Oranges")
>>> {
>>> $count[2] = $count[2] + 1;
>>> }
>>>
>>> }
>>> print "$em_key count is: $count[2]\n";
>>> exit;
>>>
>>> It give me the following results:
>>>
>>> Apple Count is: 2
>>> Oranges Count is: 1
>>>
>>> Here is the data.
>>>
>>> Apples |Sweet
>>> Oranges |Seeds
>>> Apples |Sour
>>>
>>> -----Original Message-----
>>> From: perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
>> <mailto:perl-beginner%40yahoogroups.com>
>> [mailto:perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
>> <mailto:perl-beginner%40yahoogroups.com> ]
>>> On Behalf Of Scot Robnett
>>> Sent: Wednesday, June 17, 2009 12:22 PM
>>> To: perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
>>
>>> Subject: RE: [PBML] Newbie question
>>>
>>> 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%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
>> <mailto:perl-beginner%40yahoogroups.com>
>>> [mailto:perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
>> <mailto:perl-beginner%40yahoogroups.com> ] On Behalf Of Kevin Patterson
>>> Sent: Wednesday, June 17, 2009 2:11 PM
>>> To: perl-beginner@yahoogroups.com
<mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.com>
> <mailto:perl-beginner%40yahoogroups.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]
>>>
>>> ------------------------------------
>>>
>>> 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]
>>
>>
>
> [Non-text portions of this message have been removed]
>
> [Non-text portions of this message have been removed]
>
>





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




#26657 From: merlyn@...
Date: Wed Jun 17, 2009 11:02 pm
Subject: Re: [PBML] Newbie question
merlynstoneh...
Online Now Online Now
Send Email Send Email
 
>>>>> "Kevin" == Kevin Patterson <kpatters@...> writes:

Kevin> I have it on order and reading it online now..

I hope by "reading it online" you mean you have a safari.oreilly.com account
(or access to it through some organization), and not that you have obtained an
*ILLEGAL* copy from a pirate source.

There are no *LEGAL* unrestricted copies of Learning Perl on the net.
Period. If you find one, please report it to infringement@....

Thanks.

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



#26649 From: Urban Gabor <gabaux@...>
Date: Wed Jun 17, 2009 8:15 pm
Subject: Re: [PBML] Newbie question
gabauxhu
Offline Offline
Send Email Send Email
 
Hi,

try to have a hash containing the frequencies.

IMHO it is not a Perl issue. Get some info on algorithms

Gabaux

---------------------
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]




[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
Offline Offline
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]




 
Advanced
Add to My Yahoo!      XML What's This?

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