Loading ...
Sorry, an error occurred while loading the content.

Please help me parse this data structure.

Expand Messages
  • Jhilmil Jain
    Hi, I am learning Perl. I need help to parse this data structure. My guess is that it is an array of hashes. But I cant understand how to extract the key and
    Message 1 of 6 , Apr 2, 2001
    • 0 Attachment
      Hi,
      I am learning Perl.
      I need help to parse this data structure.

      My guess is that it is an array of hashes.
      But I cant understand how to extract the key and values
      of this data structure.

      Thanks,
      Jhilmil

      $VAR1 = [

      { 'name' => 'foo',

      'type' => 'e',

      'content' => [

      { 'name' => 'head',

      'type' => 'e',

      'content' => [

      { 'type' => 't',

      'content' => 'Hello '

      },

      { 'name' => 'em',

      'type' => 'e',

      'content' => [

      { 'type' =>
      't',

      'content'
      => 'there'

      }

      ],

      'attrib' => {}

      }

      ],

      'attrib' => { 'id' => 'a'

      }

      },

      { 'name' => 'bar',

      'type' => 'e',

      'content' => [

      { 'type' => 't',

      'content' => 'Howdy'

      },

      { 'name' => 'ref',

      'type' => 'e',

      'content' => [],

      'attrib' => {}

      }

      ],

      'attrib' => {}

      },

      { 'type' => 't',

      'content' => '

      do

      '

      }

      ],

      'attrib' => {}

      }

      ];
    • Eric Thibodeau
      A while back...when I was also a domain admin, I used to do exactly the same thing without using PERL. I used a batch file that would map the share as a local
      Message 2 of 6 , Apr 3, 2001
      • 0 Attachment
        A while back...when I was also a domain admin, I used to do exactly
        the same thing without using PERL. I used a batch file that would map the
        share as a local drive, say "z", and then delete it's contents. This might
        be a way to go around the UNC problems you are encountering.

        type in "NET USE /?" from the command prompt for more info (though I am sure
        you already know all of this). I know it's a messy solution but it might
        just work (duckt tape is messy anyways! :o)

        Eric Thibodeau
        (514) 374-6204 x453
        ELECTROLINE R&D

        -----Original Message-----
        From: Christopher L. Severson [mailto:cseverson@...]
        Sent: Monday, April 02, 2001 10:11 PM
        To: 'perl-beginner@yahoogroups.com'
        Subject: RE: [PBML] Re: UNC Problem in Perl Script



        I have full access to the computer - I am a Domain Admin - if I were to
        click Start,Run, and type that in, it will pull up a box of that directory
        and show me its contents. Yes, my opendir() call does fail - it says that
        the directory does not exist. Again, if I use a local directory (i.e.
        D:\Temp) this works fine. I have not tried the command from a command
        prompt, but I am sure it would work -

        Thank you for the response....any other ideas?

        -Chris Severson

        -----Original Message-----
        From: Damien Carbery [SMTP:daymobrew@...]
        Sent: Monday, April 02, 2001 6:02 PM
        To: perl-beginner@yahoogroups.com
        Subject: [PBML] Re: UNC Problem in Perl Script

        Try entering:
        \\hak-comproom\D$\Temp
        in the Start/Run dialog. It should open an Explorer directory window.
        Of course you may not have the rights to access that directory, which
        would definitely mean you can't access it in Perl.
        Does your opendir() call fail? If so, what is the error message
        provided by $! or $?.

        The Win32::NetResource module may allow you to connect to the
        directory as a drive and then delete the files.
        I searched the group archive for "NetResource" and found a few posts
        about using this module but none seem to say what definitely works.

        Have you tried your code in a command prompt?
        For example:
        del \\hak-comproom\D$\Temp\*.pif

        --- In perl-beginner@y..., "Christopher L. Severson" <cseverson@m...>
        wrote:
        > Everyone,
        >
        > Sorry for the what seems like constant questions - I am starting to
        get
        > frustrated around this.
        >
        > I am writing a program that gets a list of all NT Workstation
        accounts from
        > the PDC, and then will delete the contents of
        > C:\temp and D:\temp on each machine.
        >
        > Part of having to do this is either going to be using the 'unlink'
        command
        > or the 'opendir' command on a UNC path.
        > This is where I am running into troubles. Even if I go in to test
        and set
        > a variable up to a UNC path (which works, I can print the variable
        and see
        > it) I cannot then use that variable in my 'opendir' command. Here
        is what
        > I am trying:
        >
        > @filelist = ();
        > $path1 = "\\\\hak-comproom\\D\$\\Temp";
        >
        > opendir (Temp, "$path1") || die "Cannot open the temp directory:
        $!";
        > @filelist = readdir Temp;
        >
        > closedir (Temp);
        >
        > Everytime I run this part of the code, it cannot open the temp
        directory.
        > However if I just print the $path1 variable, it prints out just
        like it
        > should:
        >
        > \\hak-comproom\D$\temp
        >
        > Any help/insight to this problem would be greatly appreciated. I am
        using
        > ActiveState's Perl v.5.6.0 build 615.
        >
        > TIA!
        >
        > -Chris Severson

        << File: ATT00035.htm >>





        Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
      • Damien Carbery
        ... Try it. I m too believe it will work but you can t be too sure when you re trying to track down a problem like this. Have a go with Win32::NetResource.
        Message 3 of 6 , Apr 3, 2001
        • 0 Attachment
          > I have not tried the command from a command
          > prompt, but I am sure it would work
          Try it. I'm too believe it will work but you can't be too sure when
          you're trying to track down a problem like this.

          Have a go with Win32::NetResource. Documentation is lacking as are
          samples (I searched around when the module's name came up a few months
          ago) so you'll have to experiment with it.
          I'm guessing access to Win32 API documentation could be helpful - the
          Win32 functions may have similar names and therefore functionality as
          the NetResource ones. The Win32 API docs with MSDEV often have good
          explanations of each parameter and what it returns.


          --- In perl-beginner@y..., "Christopher L. Severson" <cseverson@m...>
          wrote:
          >
          > I have full access to the computer - I am a Domain Admin - if I were
          to
          > click Start,Run, and type that in, it will pull up a box of that
          directory
          > and show me its contents. Yes, my opendir() call does fail - it
          says that
          > the directory does not exist. Again, if I use a local directory
          (i.e.
          > D:\Temp) this works fine. I have not tried the command from a
          command
          > prompt, but I am sure it would work -
          >
          > Thank you for the response....any other ideas?
          >
          > -Chris Severson
          >
          > -----Original Message-----
          > From: Damien Carbery [SMTP:daymobrew@y...]
          > Sent: Monday, April 02, 2001 6:02 PM
          > To: perl-beginner@y...
          > Subject: [PBML] Re: UNC Problem in Perl Script
          >
          > Try entering:
          > \\hak-comproom\D$\Temp
          > in the Start/Run dialog. It should open an Explorer directory
          window.
          > Of course you may not have the rights to access that directory,
          which
          > would definitely mean you can't access it in Perl.
          > Does your opendir() call fail? If so, what is the error message
          > provided by $! or $?.
          >
          > The Win32::NetResource module may allow you to connect to the
          > directory as a drive and then delete the files.
          > I searched the group archive for "NetResource" and found a few posts
          > about using this module but none seem to say what definitely works.
          >
          > Have you tried your code in a command prompt?
          > For example:
          > del \\hak-comproom\D$\Temp\*.pif
          >
          > --- In perl-beginner@y..., "Christopher L. Severson"
          <cseverson@m...>
          > wrote:
          > > Everyone,
          > >
          > > Sorry for the what seems like constant questions - I am starting
          to
          > get
          > > frustrated around this.
          > >
          > > I am writing a program that gets a list of all NT Workstation
          > accounts from
          > > the PDC, and then will delete the contents of
          > > C:\temp and D:\temp on each machine.
          > >
          > > Part of having to do this is either going to be using the 'unlink'
          > command
          > > or the 'opendir' command on a UNC path.
          > > This is where I am running into troubles. Even if I go in to test
          > and set
          > > a variable up to a UNC path (which works, I can print the variable
          > and see
          > > it) I cannot then use that variable in my 'opendir' command. Here
          > is what
          > > I am trying:
          > >
          > > @filelist = ();
          > > $path1 = "\\\\hak-comproom\\D\$\\Temp";
          > >
          > > opendir (Temp, "$path1") || die "Cannot open the temp directory:
          > $!";
          > > @filelist = readdir Temp;
          > >
          > > closedir (Temp);
          > >
          > > Everytime I run this part of the code, it cannot open the temp
          > directory.
          > > However if I just print the $path1 variable, it prints out just
          > like it
          > > should:
          > >
          > > \\hak-comproom\D$\temp
          > >
          > > Any help/insight to this problem would be greatly appreciated. I
          am
          > using
          > > ActiveState's Perl v.5.6.0 build 615.
          > >
          > > TIA!
          > >
          > > -Chris Severson
          >
          > << File: ATT00035.htm >>
        • Doug Wells
          If you have questions specifically about Win32 stuff, try looking at or posting to the Perl NT Admin mailing list
          Message 4 of 6 , Apr 3, 2001
          • 0 Attachment
            If you have questions specifically about Win32 stuff,
            try looking at or posting to the Perl NT Admin mailing
            list (http://www.topica.com/lists/perl-ntadmins/read)
            or look at Dave Roth's book "Win32 Perl Programming".
            They are great resouces.

            Good luck,

            Doug

            --- Damien Carbery <daymobrew@...> wrote:
            > > I have not tried the command from a command
            > > prompt, but I am sure it would work
            > Try it. I'm too believe it will work but you can't
            > be too sure when
            > you're trying to track down a problem like this.
            >
            > Have a go with Win32::NetResource. Documentation is
            > lacking as are
            > samples (I searched around when the module's name
            > came up a few months
            > ago) so you'll have to experiment with it.
            > I'm guessing access to Win32 API documentation could
            > be helpful - the
            > Win32 functions may have similar names and therefore
            > functionality as
            > the NetResource ones. The Win32 API docs with MSDEV
            > often have good
            > explanations of each parameter and what it returns.
            >
            >
            > --- In perl-beginner@y..., "Christopher L. Severson"
            > <cseverson@m...>
            > wrote:
            > >
            > > I have full access to the computer - I am a Domain
            > Admin - if I were
            > to
            > > click Start,Run, and type that in, it will pull up
            > a box of that
            > directory
            > > and show me its contents. Yes, my opendir() call
            > does fail - it
            > says that
            > > the directory does not exist. Again, if I use a
            > local directory
            > (i.e.
            > > D:\Temp) this works fine. I have not tried the
            > command from a
            > command
            > > prompt, but I am sure it would work -
            > >
            > > Thank you for the response....any other ideas?
            > >
            > > -Chris Severson
            > >
            > > -----Original Message-----
            > > From: Damien Carbery [SMTP:daymobrew@y...]
            > > Sent: Monday, April 02, 2001 6:02 PM
            > > To: perl-beginner@y...
            > > Subject: [PBML] Re: UNC Problem in Perl Script
            > >
            > > Try entering:
            > > \\hak-comproom\D$\Temp
            > > in the Start/Run dialog. It should open an
            > Explorer directory
            > window.
            > > Of course you may not have the rights to access
            > that directory,
            > which
            > > would definitely mean you can't access it in Perl.
            > > Does your opendir() call fail? If so, what is the
            > error message
            > > provided by $! or $?.
            > >
            > > The Win32::NetResource module may allow you to
            > connect to the
            > > directory as a drive and then delete the files.
            > > I searched the group archive for "NetResource" and
            > found a few posts
            > > about using this module but none seem to say what
            > definitely works.
            > >
            > > Have you tried your code in a command prompt?
            > > For example:
            > > del \\hak-comproom\D$\Temp\*.pif
            > >
            > > --- In perl-beginner@y..., "Christopher L.
            > Severson"
            > <cseverson@m...>
            > > wrote:
            > > > Everyone,
            > > >
            > > > Sorry for the what seems like constant questions
            > - I am starting
            > to
            > > get
            > > > frustrated around this.
            > > >
            > > > I am writing a program that gets a list of all
            > NT Workstation
            > > accounts from
            > > > the PDC, and then will delete the contents of
            > > > C:\temp and D:\temp on each machine.
            > > >
            > > > Part of having to do this is either going to be
            > using the 'unlink'
            > > command
            > > > or the 'opendir' command on a UNC path.
            > > > This is where I am running into troubles. Even
            > if I go in to test
            > > and set
            > > > a variable up to a UNC path (which works, I can
            > print the variable
            > > and see
            > > > it) I cannot then use that variable in my
            > 'opendir' command. Here
            > > is what
            > > > I am trying:
            > > >
            > > > @filelist = ();
            > > > $path1 = "\\\\hak-comproom\\D\$\\Temp";
            > > >
            > > > opendir (Temp, "$path1") || die "Cannot open the
            > temp directory:
            > > $!";
            > > > @filelist = readdir Temp;
            > > >
            > > > closedir (Temp);
            > > >
            > > > Everytime I run this part of the code, it cannot
            > open the temp
            > > directory.
            > > > However if I just print the $path1 variable, it
            > prints out just
            > > like it
            > > > should:
            > > >
            > > > \\hak-comproom\D$\temp
            > > >
            > > > Any help/insight to this problem would be
            > greatly appreciated. I
            > am
            > > using
            > > > ActiveState's Perl v.5.6.0 build 615.
            > > >
            > > > TIA!
            > > >
            > > > -Chris Severson
            > >
            > > << File: ATT00035.htm >>
            >
            >


            __________________________________________________
            Do You Yahoo!?
            Get email at your own domain with Yahoo! Mail.
            http://personal.mail.yahoo.com/
          • Damien Carbery
            Look up perldsc (Perl Data Structures Cookbook). It says you access an element in the array of hashes as: $AoH[0]{lead} = fred ; To access the whole thing: #
            Message 5 of 6 , Apr 3, 2001
            • 0 Attachment
              Look up perldsc (Perl Data Structures Cookbook).

              It says you access an element in the array of hashes as:
              $AoH[0]{lead} = "fred";

              To access the whole thing:
              # print the whole thing one at a time
              for $i ( 0 .. $#AoH ) {
              for $role ( keys %{ $AoH[$i] } ) {
              print "elt $i $role is $AoH[$i]{$role}\n";
              }
              }

              --- In perl-beginner@y..., Jhilmil Jain <jhilmilj@E...> wrote:
              >
              >
              > Hi,
              > I am learning Perl.
              > I need help to parse this data structure.
              >
              > My guess is that it is an array of hashes.
              > But I cant understand how to extract the key and values
              > of this data structure.
              >
              > Thanks,
              > Jhilmil
              >
              > $VAR1 = [
              >
              > { 'name' => 'foo',
              >
              > 'type' => 'e',
              >
              > 'content' => [
              >
              > { 'name' => 'head',
              >
              > 'type' => 'e',
              >
              > 'content' => [
              >
              > { 'type' => 't',
              >
              > 'content' => 'Hello '
              >
              > },
              >
              > { 'name' => 'em',
              >
              > 'type' => 'e',
              >
              > 'content' => [
              >
              > {
              'type' =>
              > 't',
              >
              >
              'content'
              > => 'there'
              >
              > }
              >
              > ],
              >
              > 'attrib' => {}
              >
              > }
              >
              > ],
              >
              > 'attrib' => { 'id' => 'a'
              >
              > }
              >
              > },
              >
              > { 'name' => 'bar',
              >
              > 'type' => 'e',
              >
              > 'content' => [
              >
              > { 'type' => 't',
              >
              > 'content' => 'Howdy'
              >
              > },
              >
              > { 'name' => 'ref',
              >
              > 'type' => 'e',
              >
              > 'content' => [],
              >
              > 'attrib' => {}
              >
              > }
              >
              > ],
              >
              > 'attrib' => {}
              >
              > },
              >
              > { 'type' => 't',
              >
              > 'content' => '
              >
              > do
              >
              > '
              >
              > }
              >
              > ],
              >
              > 'attrib' => {}
              >
              > }
              >
              > ];
            Your message has been successfully submitted and would be delivered to recipients shortly.