<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: perl split function question in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-split-function-question/m-p/3095156#M145672</link>
    <description>Hmm. Interesting. Put a space between '%s 'x9 and ."\n".</description>
    <pubDate>Sat, 18 Oct 2003 06:41:01 GMT</pubDate>
    <dc:creator>Jordan Bean</dc:creator>
    <dc:date>2003-10-18T06:41:01Z</dc:date>
    <item>
      <title>perl split function question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-split-function-question/m-p/3095147#M145663</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;I have a mixed delimiter password file with both : and ,,,. &lt;BR /&gt;&lt;BR /&gt;How can I use the perl split function to load the password file into an array without the delimeters ?&lt;BR /&gt;&lt;BR /&gt;I know this is easy with awk but what about split ?&lt;BR /&gt;&lt;BR /&gt;Jeff</description>
      <pubDate>Thu, 16 Oct 2003 10:16:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-split-function-question/m-p/3095147#M145663</guid>
      <dc:creator>Jeff Picton</dc:creator>
      <dc:date>2003-10-16T10:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: perl split function question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-split-function-question/m-p/3095148#M145664</link>
      <description>@pwent = split(/:/, $_);&lt;BR /&gt;@gecos = split(/,/, $pwent[4]);&lt;BR /&gt; &lt;BR /&gt;HTH.</description>
      <pubDate>Thu, 16 Oct 2003 11:04:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-split-function-question/m-p/3095148#M145664</guid>
      <dc:creator>Brian Bergstrand</dc:creator>
      <dc:date>2003-10-16T11:04:48Z</dc:date>
    </item>
    <item>
      <title>Re: perl split function question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-split-function-question/m-p/3095149#M145665</link>
      <description>Here is a example that can serve to help :&lt;BR /&gt; word can be split into characters, a sentence split into words and a paragraph split into sentences: &lt;BR /&gt;&lt;BR /&gt;@chars = split(//, $word);&lt;BR /&gt;@words = split(/ /, $sentence);&lt;BR /&gt;@sentences = split(/\./, $paragraph);&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 16 Oct 2003 11:08:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-split-function-question/m-p/3095149#M145665</guid>
      <dc:creator>Paddy_1</dc:creator>
      <dc:date>2003-10-16T11:08:00Z</dc:date>
    </item>
    <item>
      <title>Re: perl split function question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-split-function-question/m-p/3095150#M145666</link>
      <description>Hi &lt;BR /&gt;&lt;BR /&gt;Thats fine but I need to print the WHOLE file (as an array) without delimeters. Brians suggestion only enables one to print a single field of the array.</description>
      <pubDate>Thu, 16 Oct 2003 11:14:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-split-function-question/m-p/3095150#M145666</guid>
      <dc:creator>Jeff Picton</dc:creator>
      <dc:date>2003-10-16T11:14:12Z</dc:date>
    </item>
    <item>
      <title>Re: perl split function question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-split-function-question/m-p/3095151#M145667</link>
      <description>I'm not sure what you mean. You want each line of the file as a separate entry in an array? And each entry should be void of the : and , delimeters?&lt;BR /&gt; &lt;BR /&gt;Could you better describe your requirements?&lt;BR /&gt; &lt;BR /&gt;Thanks.</description>
      <pubDate>Thu, 16 Oct 2003 11:25:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-split-function-question/m-p/3095151#M145667</guid>
      <dc:creator>Brian Bergstrand</dc:creator>
      <dc:date>2003-10-16T11:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: perl split function question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-split-function-question/m-p/3095152#M145668</link>
      <description>You actually have two distinct options: split and getpwent. The latter works on the system passwd file only.&lt;BR /&gt;&lt;BR /&gt;If you want to sort, then I'd use a hash. Otherwise, I'd print each line as its read and munged. A simple array isn't necessary.&lt;BR /&gt;&lt;BR /&gt;I'm pulling the following snippets from memory, so please excuse any errors.&lt;BR /&gt;&lt;BR /&gt;1. No sorting:&lt;BR /&gt;&lt;BR /&gt;perl -pe 'tr/:,/ /;' &amp;lt; passwd &amp;gt; passwd.out&lt;BR /&gt;&lt;BR /&gt;2. Sorting:&lt;BR /&gt;&lt;BR /&gt;$h={};&lt;BR /&gt;while(&amp;lt;&amp;gt;){ chomp; ($u,@u)=split /[:,]/; $h-&amp;gt;{$u}=[@u]; }&lt;BR /&gt;foreach ( sort keys %$h ) { printf '%s 'x9."\n", $_, @{$h-&amp;gt;{$_}}; }&lt;BR /&gt;&lt;BR /&gt;3. System routine. No sorting:&lt;BR /&gt;&lt;BR /&gt;setpwent;&lt;BR /&gt;while(@_=getpwent){printf '%s 'x9."\n",@_;}&lt;BR /&gt;endpwent;&lt;BR /&gt;&lt;BR /&gt;4. System routine. Sorted:&lt;BR /&gt;&lt;BR /&gt;$h={};&lt;BR /&gt;setpwent;&lt;BR /&gt;while(($u,@u)=getpwent){ $h-&amp;gt;{$u}=[@u]; }&lt;BR /&gt;endpwent;&lt;BR /&gt;foreach ( sort keys %$h ) { printf '%s 'x9."\n", $_, @{$h-&amp;gt;{$_}}; }&lt;BR /&gt;&lt;BR /&gt;It's late. Let me know if I goofed.</description>
      <pubDate>Fri, 17 Oct 2003 02:00:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-split-function-question/m-p/3095152#M145668</guid>
      <dc:creator>Jordan Bean</dc:creator>
      <dc:date>2003-10-17T02:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: perl split function question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-split-function-question/m-p/3095153#M145669</link>
      <description>If I understand the question correctly you want to finish up with one array that contains every line of the password file but without delimiters.  Simplest thing here is to just translate all the delimiters to spaces as in "tr /:/ /;" and "tr /,/ /;" and "push" the result onto an array.  &lt;BR /&gt; &lt;BR /&gt;If you want to access each individual field of each individual  line of the file you will need a multi-dimentional array. Multi-dimentional arrays are a pain in perl, in my view so I would go with the previous suggest and make a hash of arrays.  First translate the ","'s to spaces (or to ":" if you want them as seperate fields) then split on the ":" into an array which you then put into a hash as in "$myhash{$array[0]}=[ @array ].&lt;BR /&gt; &lt;BR /&gt;You would access an user fred'd uid for example with $myhash{fred}[2].</description>
      <pubDate>Fri, 17 Oct 2003 02:41:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-split-function-question/m-p/3095153#M145669</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2003-10-17T02:41:15Z</dc:date>
    </item>
    <item>
      <title>Re: perl split function question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-split-function-question/m-p/3095154#M145670</link>
      <description>Why not use perl's buildin functions to access the password file info?&lt;BR /&gt; &lt;BR /&gt;perldoc -f endpwent&lt;BR /&gt;perldoc -f getpwent&lt;BR /&gt;perldoc -f getpwnam&lt;BR /&gt;perldoc -f getpwuid&lt;BR /&gt;perldoc -f setpwent&lt;BR /&gt; &lt;BR /&gt;Enjoy, have FUN! H.Merijn</description>
      <pubDate>Fri, 17 Oct 2003 03:33:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-split-function-question/m-p/3095154#M145670</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2003-10-17T03:33:36Z</dc:date>
    </item>
    <item>
      <title>Re: perl split function question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-split-function-question/m-p/3095155#M145671</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;Thanks for all the replies.&lt;BR /&gt;&lt;BR /&gt;I tried the sort method but there is a syntax error on the printf statement which I cannot find&lt;BR /&gt;&lt;BR /&gt;Jeff</description>
      <pubDate>Fri, 17 Oct 2003 03:41:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-split-function-question/m-p/3095155#M145671</guid>
      <dc:creator>Jeff Picton</dc:creator>
      <dc:date>2003-10-17T03:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: perl split function question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-split-function-question/m-p/3095156#M145672</link>
      <description>Hmm. Interesting. Put a space between '%s 'x9 and ."\n".</description>
      <pubDate>Sat, 18 Oct 2003 06:41:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-split-function-question/m-p/3095156#M145672</guid>
      <dc:creator>Jordan Bean</dc:creator>
      <dc:date>2003-10-18T06:41:01Z</dc:date>
    </item>
  </channel>
</rss>

