Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

adding functionality
Here is the latest version of my script:

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

my $Pixarport = 7498;
my $host = "lex";
my $Pixarfile = $Pixarport."@".$host;
my @input;
my $line;
my $line_number;
my $file_length;
my @features_array;
my @handles_array;
my $handles;
my $features;
my $sizeof;
my $counter = 0;
my $answer;
my $string;
my $userid = `whoami`;

@input = `cat clicenses_output`;
$file_length = scalar(@input);

print "Is ".$userid." your userid (Y or N)?";
$answer = <STDIN>;
if ($answer =~ /^[nN]$/) {
print "Enter your userid: ";
chomp($userid = <STDIN> );
}elsif ($answer =~ /^[yY]$/) {
print $userid." is your userid.\n";
}

print "Do you wish to:"."\n";
print "1) remove all of your floating licenses at
once"."\n";
print "2) remove them one at a time"."\n";
$answer = <STDIN>;

if ($answer == 1) {
foreach ($line_number = 0; $line_number <=
$file_length; $line_number++){
last if ($line_number == $file_length);
$line = $input[$line_number];
next unless $line =~ /\S/;
$line =~ s/^\s+//;
@features_array = split /\s/, $line ;
#split $line along whitespace and place into an array
LOOKING_USERS: if ($features_array[0] eq
"Users") {
($features = $features_array[2]) =~ s/://;
#assign second element into $features and remove
colon
$line_number++;
}
$line = $input[$line_number];
if ($line =~ /Users/) {
@features_array = split /\s/, $line;
#split $line along whitespace and place into an array
goto LOOKING_USERS;
}
next unless $line =~ /\S/;
$line =~ s/^\s+//;
@handles_array = split /\s/, $line;    #split
$line along whitespace and place into an array
$sizeof = scalar(@handles_array);
if ($sizeof >= 9 && $handles_array[0] eq
$userid){
($handles = $handles_array[5]) =~ s/\),//;
#assign ninth element into $handles and remove ),
$string = join " ", @handles_array;
print $string."\n";
print "lmutil lmremove -c ".$Pixarfile."
-h ".$features." ".$host." ".$Pixarport."
".$handles."\n";
}
}
}

Basically, I'm trying to add some extra functionality
to the script.  I want the user to be able to pick
between have the script automatically remove all of
the licenses for them or query them like so:

Remove such-and-such license (Y or N)?

What would be the best way of going about this?

Report this thread to moderator Post Follow-up to this message
Old Post
Christopher Spears
12-16-04 08:56 AM


Re: adding functionality

Christopher Spears wrote:
> Here is the latest version of my script:
>
> #!/usr/bin/perl -w
> use strict;
>
> my $Pixarport = 7498;
> my $host = "lex";
> my $Pixarfile = $Pixarport."@".$host;
> my @input;
> my $line;
> my $line_number;
> my $file_length;
> my @features_array;
> my @handles_array;
> my $handles;
> my $features;
> my $sizeof;
> my $counter = 0;
> my $answer;
> my $string;
> my $userid = `whoami`;
>
> @input = `cat clicenses_output`;

Why not

my @input = `cat ...

here instead of my'ing it above and then assigning to it here?

> $file_length = scalar(@input);

Sama as above...

> print "Is ".$userid." your userid (Y or N)?";

Why not

print "Is $userid your userid (Y or N)?";

the "".$var."" is pointless and confusing...

> $answer = <STDIN>;
> if ($answer =~ /^[nN]$/) {
>     print "Enter your userid: ";
>     chomp($userid = <STDIN> );
> }elsif ($answer =~ /^[yY]$/) {
>     print $userid." is your userid.\n";


same as above...

> }
>
> print "Do you wish to:"."\n";

same as above...

> print "1) remove all of your floating licenses at
> once"."\n";

same as above...

> print "2) remove them one at a time"."\n";


same as above...

You could even use a here doc:

print <<OPTION;
Do you wish to:
1) remove all ...
2) remove them ....
OPTION

> $answer = <STDIN>;

same as first "why not" above...

i know that wasn't your original question but it may be easier for you
if the code was more readable...

HTH :)

Lee.M - JupiterHost.Net

Report this thread to moderator Post Follow-up to this message
Old Post
JupiterHost.Net
12-16-04 01:56 PM


RE: adding functionality
Christopher Spears <cspears2002@yahoo.com> wrote:

: Here is the latest version of my script:

I think you are using the wrong approach to parsing
this output. You're making it a lot more complicated
than it needs to be. I omitted the report and question
sections. Your report data is in %licenses.

Read 'perldsc' for info on printing from a hash of
arrays (HoA).

I use a sub routine to fetch the licenses. In that
sub I remove all lines except the ones starting with a
" and those containing a handle.

use strict;
use warnings;
use Data::Dumper 'Dumper';

my $name;
my %licenses;
foreach ( fetch_licenses() ) {
if ( /"([^"]+)/ ) {
$name = $1;

} elsif ( m|lex/\d+ (\d+)| ) {
push @{ $licenses{ $name } }, $1;
}
}

print Dumper \%licenses;


sub fetch_licenses {
my @raw_licenses = `cat clicenses_output`;

# keep only license names and handles
return grep { m/^\s+"/ or m|\(lex/\d+ \d+\)| } @raw_licenses;
}

__END__

Sometimes it necessary to scrap what you are doing
and just start again.

HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328


Report this thread to moderator Post Follow-up to this message
Old Post
Charles K. Clarkson
12-16-04 08:59 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:52 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.