Using the split function

Discussion in 'Perl Misc' started by Simon, Jul 17, 2007.

  1. Simon

    Simon Guest

    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.
    Simon, Jul 17, 2007
    #1
    1. Advertising

  2. Simon

    Lars Eighner Guest

    In our last episode,
    <Ih1ni.8443$>,
    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.

    > In the above, I printed the $line, just so you guys could see what is
    > returned.



    --
    Lars Eighner <http://larseighner.com/> <http://myspace.com/larseighner>
    Countdown: 553 days to go.
    Owing to massive spam from googlegroups, I do not see most posts from there.
    Lars Eighner, Jul 17, 2007
    #2
    1. Advertising

  3. On Tue, 17 Jul 2007 10:58:48 GMT, "Simon" <> wrote:

    >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
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
    Michele Dondi, Jul 17, 2007
    #3
  4. On 17 Jul 2007 11:47:13 GMT, Lars Eighner <>
    wrote:

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


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


    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
    Michele Dondi, Jul 17, 2007
    #4
  5. Simon

    Simon Guest

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

    "Lars Eighner" <> wrote in message
    news:...
    > In our last episode,
    > <Ih1ni.8443$>,
    > 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.
    >
    >> In the above, I printed the $line, just so you guys could see what is
    >> returned.

    >
    >
    > --
    > Lars Eighner <http://larseighner.com/>
    > <http://myspace.com/larseighner>
    > Countdown: 553 days to go.
    > Owing to massive spam from googlegroups, I do not see most posts from
    > there.
    Simon, Jul 17, 2007
    #5
  6. Jim Gibson wrote:
    > In article <Ih1ni.8443$>, Simon
    > <> wrote:
    >>
    >> #================================================= Read a Computer List.
    >> open (Store, "< systems.txt") or die "can't open systems.txt: $!";
    >> foreach $line (<Store>) {

    >
    > 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
    --
    Perl isn't a toolbox, but a small machine shop where you
    can special-order certain sorts of tools at low cost and
    in short order. -- Larry Wall
    John W. Krahn, Jul 17, 2007
    #6
  7. On Tue, 17 Jul 2007 09:50:29 -0700, Jim Gibson
    <> wrote:

    >> open (Store, "< systems.txt") or die "can't open systems.txt: $!";
    >> foreach $line (<Store>) {

    >
    >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
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
    Michele Dondi, Jul 17, 2007
    #7
  8. Simon <> wrote:

    > "Lars Eighner" <> wrote in message
    > news:...
    >> In our last episode,
    >> <Ih1ni.8443$>,
    >> the lovely and talented Simon
    >> broadcast on comp.lang.perl.misc:


    >>> Im
    >>> having
    >>> problems with the split function. Please see below..

    >>
    >> Sounds suspiciously like homework.
    >>
    >>> Ive deliberately left out the split function



    > Eighner sounds suspiciously like "a.....s"

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

    "abducts" ?

    "abscess" ?

    "assumes" ?

    "accuses"?




    Anyway, sounds suspiciously like "killfile me please".

    As you wish.


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
    Tad McClellan, Jul 17, 2007
    #8
  9. On Tue, 17 Jul 2007 17:36:34 -0500, Tad McClellan
    <> wrote:

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


    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
    Michele Dondi, Jul 19, 2007
    #9
  10. On 19 Jul 2007 13:27:50 GMT, Abigail <> wrote:

    >~~ 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
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
    Michele Dondi, Jul 19, 2007
    #10
  11. Simon

    Ian Wilson Guest

    Abigail wrote:
    > _
    > Michele Dondi () wrote on VLXX September MCMXCIII
    > in <URL:news:>:
    > ~~ On Tue, 17 Jul 2007 17:36:34 -0500, Tad McClellan
    > ~~ <> wrote:
    > ~~
    > ~~ >>>> 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


    <40 lines omitted>

    > 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?
    Ian Wilson, Jul 19, 2007
    #11
  12. Simon

    Lars Eighner Guest

    In our last episode, <>, the
    lovely and talented Michele Dondi broadcast on comp.lang.perl.misc:

    > On 19 Jul 2007 13:27:50 GMT, Abigail <> wrote:


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


    It's a one-liner in grep. The right tool for the job, and all.

    --
    Lars Eighner <http://larseighner.com/> <http://myspace.com/larseighner>
    Countdown: 551 days to go.
    Owing to massive spam from googlegroups, I do not see most posts from there.
    Lars Eighner, Jul 19, 2007
    #12
  13. On 19 Jul 2007 14:32:38 GMT, Lars Eighner <>
    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?


    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
    Michele Dondi, Jul 19, 2007
    #13
  14. Michele Dondi <> wrote:
    >On 19 Jul 2007 14:32:38 GMT, Lars Eighner <>
    >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)

    --
    Steven O'Neill
    Brooklyn, NY http://www.panix.com/~steveo
    Steven M. O'Neill, Jul 19, 2007
    #14
  15. On Thu, 19 Jul 2007 17:12:04 +0000 (UTC), (Steven M.
    O'Neill) wrote:

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


    Fair enough...


    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
    Michele Dondi, Jul 19, 2007
    #15
  16. Abigail <> wrote:
    > _
    >Steven M. O'Neill () wrote on VLXX September MCMXCIII in
    ><URL:news:f7o614$6ht$>:
    >?? Michele Dondi <> wrote:
    >?? >On 19 Jul 2007 14:32:38 GMT, Lars Eighner <>
    >?? >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.

    --
    Steven O'Neill
    Brooklyn, NY http://www.panix.com/~steveo
    Steven M. O'Neill, Jul 20, 2007
    #16
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    466
  2. Carlos Ribeiro
    Replies:
    11
    Views:
    696
    Alex Martelli
    Sep 17, 2004
  3. trans.  (T. Onoma)

    split on '' (and another for split -1)

    trans. (T. Onoma), Dec 27, 2004, in forum: Ruby
    Replies:
    10
    Views:
    213
    Florian Gross
    Dec 28, 2004
  4. Sam Kong
    Replies:
    5
    Views:
    238
    Rick DeNatale
    Aug 12, 2006
  5. Stanley Xu
    Replies:
    2
    Views:
    604
    Stanley Xu
    Mar 23, 2011
Loading...

Share This Page