Using the split function

S

Simon

Hi guys.
Would appreciate very much your help on this one.
What I want to do is:
Create a perl script that:
a) Reads a computer list (done)
b) Connects to each one (done)
c) Uses reg.exe to query a registry value (done)
d) Pipe the computer with its BuildVersion number to the appropriate text
file according to Buildverson number retrieved (having problems). Im having
problems with the split function. Please see below..


================================================================= go.pl

sub RunRegQuery {
open (REGQUERY, "reg query \"\\\\$System\\HKLM\\Software\\test\" /v
BuildVersion|");
while (<REGQUERY>) {
@lines = <REGQUERY>;
foreach $line (@lines) {
chomp $line;
print "$line\n";
}
}
}

#================================================= Create files for logging.
open U,">unknown.txt" or die "unknown.txt $!";
open H,">6.11.txt" or die "6.11.txt $!";
open S,">6.7.txt" or die "6.7.txt $!";
open L,">6.5.txt" or die "6.5.txt $!";
open C,">6.2.txt" or die "6.2.txt $!";

#================================================= Read a Computer List.
open (Store, "< systems.txt") or die "can't open systems.txt: $!";
foreach $line (<Store>) {
chomp($line);
$System = $line;
$result = system ("net use \\\\$System\\ipc\$ \"password\"
/user:$System\\administrator");
if ($result !=0) { #if not successful
print U "$System: Unreachable\n";
}
else {
print "$System: Successful.\n";
sleep 3;
RunRegQuery();
system ("net use \\\\$System\\ipc\$ /delete /y >
2NUL > NUL"); # Delete previous connection
}
}
close (Store);
exit;
--------------------------------------------------------- EOF
=====================================================================
Output:
C:\@>go.pl
The command completed successfully.

predator: Successful.
! REG.EXE VERSION 3.0

HKEY_LOCAL_MACHINE\Software\test
BuildVersion REG_SZ 6.11


C:\@>
================================================================= Comments:

Ive deliberately left out the split function to make this easier to read, as
this is where
Im having problems.

What Im trying to do is grab the following line in the above output:

BuildVersion REG_SZ 6.11

and then, write

$System: 6.11

to the appropriate filehandle.

For example, if the value is 6.11, write "$System 6.11" to the 6.11.txt
file, then continue through the computer list.
I know I have to use a split function (I believe), but having big issues
with it.
In the above, I printed the $line, just so you guys could see what is
returned.
 
L

Lars Eighner

In our last episode,
the lovely and talented Simon
broadcast on comp.lang.perl.misc:
Hi guys.
Would appreciate very much your help on this one.
What I want to do is:
Create a perl script that:
a) Reads a computer list (done)
b) Connects to each one (done)
c) Uses reg.exe to query a registry value (done)
d) Pipe the computer with its BuildVersion number to the appropriate text
file according to Buildverson number retrieved (having problems). Im having
problems with the split function. Please see below..

Sounds suspiciously like homework.
Ive deliberately left out the split function to make this easier to read, as
this is where Im having problems.

Other than just doing you homework for you, how can we help you if we don't
see what you are trying?

What Im trying to do is grab the following line in the above output:
BuildVersion REG_SZ 6.11
and then, write
$System: 6.11
to the appropriate filehandle.
For example, if the value is 6.11, write "$System 6.11" to the 6.11.txt
file, then continue through the computer list.
I know I have to use a split function (I believe),

Why do you believe that? From what I've seen, I'd try matching.
but having big issues with it.

What issues? Let's see what you have tried that suggests you have even
looked up split for yourself.
 
M

Michele Dondi

What Im trying to do is grab the following line in the above output:

BuildVersion REG_SZ 6.11

and then, write

$System: 6.11

Is $System literal or a variable? I'm assuming the latter in what
follows. (I may also read the rest of your post but you made it too
verbose for the actual issue being discussed.)
to the appropriate filehandle.

print $fh "$System: ", (split)[2];
For example, if the value is 6.11, write "$System 6.11" to the 6.11.txt
file, then continue through the computer list.
I know I have to use a split function (I believe), but having big issues
with it.

I would help if you could explain which ones...


Michele
 
M

Michele Dondi

Why do you believe that? From what I've seen, I'd try matching.

Well, no: if lines can be trusted to be in that "format", then split()
is probably the best way to go.


Michele
 
S

Simon

Thanks Lars for your help.
Most appreciated!
Eighner sounds suspiciously like "a.....s"
 
J

John W. Krahn

Jim said:
Here you read all of the lines from systems.txt into an anonymous
array, and then iterate over the elements of that array.

s/(?s:anonymous.)?array/list/g



John
 
M

Michele Dondi

Here you read all of the lines from systems.txt into an anonymous ^^^^^^^^^
array, and then iterate over the elements of that array. If you only
^^^^^

Well, not really...
need one line at a time, it is better to use a while loop:

while( my $line = <Store> ) {
...
}

Always true!


Michele
 
T

Tad McClellan

Simon said:
Eighner sounds suspiciously like "a.....s"
^^^^^^^
^^^^^^^

"abducts" ?

"abscess" ?

"assumes" ?

"accuses"?




Anyway, (e-mail address removed) sounds suspiciously like "killfile me please".

As you wish.
 
M

Michele Dondi

^^^^^^^
^^^^^^^

"abducts" ?

"abscess" ?

"assumes" ?

"accuses"?

I thought it may have been something /^ass/, not "assumes", but I
can't think of anything significant... that "s" at the end defies my
poor English knowledge.


Michele
 
M

Michele Dondi

~~ I thought it may have been something /^ass/, not "assumes", but I
~~ can't think of anything significant... that "s" at the end defies my
~~ poor English knowledge.


abasers abashes abasias abaters abators abattis abduces abducts abelias

Incredible what a man can do with /usr/dict/words and a perl
interpreter...
asramas assails assents asserts assigns assists assizes assoils assorts

I vote for "assoils" the significance of which I don't know, but I
assumes to be an alternative spelling of "asshole"...


Michele
 
I

Ian Wilson

Abigail said:
_
Michele Dondi ([email protected]) wrote on VLXX September MCMXCIII
in <URL:~~ On Tue, 17 Jul 2007 17:36:34 -0500, Tad McClellan
~~
~~ >>>> Ive deliberately left out the split function
~~ >
~~ >
~~ >> Eighner sounds suspiciously like "a.....s"
~~ > ^^^^^^^
~~ > ^^^^^^^
~~ >"abducts" ?
~~ >"abscess" ?
~~ >"assumes" ?
~~ >"accuses"?
~~
~~ I thought it may have been something /^ass/, not "assumes", but I
~~ can't think of anything significant... that "s" at the end defies my
~~ poor English knowledge.


abasers abashes abasias abaters abators abattis abduces abducts abelias
abiders abioses abiosis abjures ablates ablauts ablings abounds abrades
abscess abseils absents absorbs absurds abulias abusers abvolts abwatts

aurochs auroras ausubos auteurs authors autisms autobus autumns auxeses
auxesis avatars avenges avenses avenues avgases aviates avidins avocets
avosets avowals avowers avulses awakens aweless awnings awnless axillas
axseeds azaleas azygous

Is there a bonus for applying Text::Soundex to work out which ones sound
like Eighner?
 
S

Steven M. O'Neill

Michele Dondi said:
It can be a one-liner in Perl too. Can grep format the output that
way?

It doesn't need to.

:~>grep '^a.....s$' words | fmt
abigeus abiosis abortus abraxas abscess absciss acerous acetous
acinous acolous acomous actless actress aculeus acyesis addlins
address adipous adpress adzooks aeneous aerobus agamous ageless
aggress agnosis agogics agynous aidless aimless airless aitesis
algesis algosis aliptes allness alumnus amaltas amanous ambiens
ambitus amellus amorous amuguis anights animous annates annulus
anoesis anurous anxious anyways aphesis aphides aphodus apieces
apodous apropos apsides aptness apyrous aqueous arbutus archeus
arduous argeers arillus armless artless ascites asepsis ashless
assizes atelets atheous atokous atomics attacus auletes aureous
aurochs autobus auxesis avenous avidous awnless azotous azurous
azygous azymous

(not sure why my output is so much less than Abigail's)
 
S

Steven M. O'Neill

Abigail said:
_
Steven M. O'Neill ([email protected]) wrote on VLXX September MCMXCIII in
<URL:?? >On 19 Jul 2007 14:32:38 GMT, Lars Eighner <[email protected]>
?? >wrote:
?? >
?? >>> Incredible what a man can do with /usr/dict/words and a perl
?? >>> interpreter...
?? >>
?? >>It's a one-liner in grep. The right tool for the job, and all.
?? >
?? >It can be a one-liner in Perl too. Can grep format the output that
?? >way?
??
?? It doesn't need to.
??
?? :~>grep '^a.....s$' words | fmt
?? abigeus abiosis abortus abraxas abscess absciss acerous acetous
?? acinous acolous acomous actless actress aculeus acyesis addlins
?? address adipous adpress adzooks aeneous aerobus agamous ageless
?? aggress agnosis agogics agynous aidless aimless airless aitesis
?? algesis algosis aliptes allness alumnus amaltas amanous ambiens
?? ambitus amellus amorous amuguis anights animous annates annulus
?? anoesis anurous anxious anyways aphesis aphides aphodus apieces
?? apodous apropos apsides aptness apyrous aqueous arbutus archeus
?? arduous argeers arillus armless artless ascites asepsis ashless
?? assizes atelets atheous atokous atomics attacus auletes aureous
?? aurochs autobus auxesis avenous avidous awnless azotous azurous
?? azygous azymous
??
?? (not sure why my output is so much less than Abigail's)

I guess I used a different line than you did.

Either that, or a different words file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top