<?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 scripting in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting/m-p/3342821#M190990</link>
    <description>first 4 characters of input&lt;BR /&gt;&lt;BR /&gt;chomp (my $bld = &lt;STDIN&gt;);&lt;BR /&gt;length ($bld) &amp;gt; 4 and $bld = substr $bld, 0, 4;&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;$bld =~ s/^(....).*/$1/;&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;length ($bld) &amp;gt; 4 and $bld = join "", (split //, $bld, -1)[0..3];&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;use your imagination ...&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn&lt;/STDIN&gt;</description>
    <pubDate>Thu, 29 Jul 2004 00:24:01 GMT</pubDate>
    <dc:creator>H.Merijn Brand (procura</dc:creator>
    <dc:date>2004-07-29T00:24:01Z</dc:date>
    <item>
      <title>Perl scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting/m-p/3342814#M190983</link>
      <description>I had great replies that have fixed my errors in my bad scripting of perl. (Thank you Rodney and Procura!). So I thought I should post new, since it is about new ideas that I want my script to do.&lt;BR /&gt;&lt;BR /&gt;I would like when the user enters in the building to save the first 4 chars of that word to a variable. This I will use in naming the files later on.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Here is the script...&lt;BR /&gt;#!/opt/perl/bin/perl&lt;BR /&gt;&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;&lt;BR /&gt;system ("clear"); #Clear the screen&lt;BR /&gt;my $acode = 204;&lt;BR /&gt;&lt;BR /&gt;print "Enter BLD &amp;gt;";&lt;BR /&gt;chomp (my $bld = &lt;STDIN&gt;);&lt;BR /&gt;print "Enter room&amp;gt;";&lt;BR /&gt;chomp (my $room = &lt;STDIN&gt;);&lt;BR /&gt;&lt;BR /&gt;open (inp, "&lt;PRTDIST&gt;&lt;/PRTDIST&gt;open my $fc, "&amp;gt;fileC" or die "fileC: $!";&lt;BR /&gt;open my $ft, "&amp;gt;fileT" or die "fileT: $!";&lt;BR /&gt;open my $fo, "&amp;gt;fileO" or die "fileO: $!";&lt;BR /&gt;while (&lt;INP&gt;) {&lt;BR /&gt;chomp;  # Will remove the leading , or new line&lt;BR /&gt;my @a = split /,/, $_, -1;&lt;BR /&gt;my $f = /TELN/ ? $ft : /CUST/? $fc : $fo;&lt;BR /&gt;print $f join "," =&amp;gt; $acode.$a[0], $bld, $room, $a[1], $a[2], "\n";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Second, I need to manipulate one of the files (fileC). Do I need to open this file, or is it still open? I want to pull the first column and surround the text with '  '. (This will be used in an sql query)&lt;BR /&gt;Do I need to assign it to an array? I would like to print it to screen first, how would I do that.&lt;BR /&gt;&lt;BR /&gt;My further quest would be to call an sql query with the data that is in that file after it has been manipulated.&lt;BR /&gt;&lt;BR /&gt;Would I then call an script.sql thru perl, that will used fileC-1 for it's data, or can it be all done thru perl. I have never seen that before.&lt;BR /&gt;&lt;/INP&gt;&lt;/STDIN&gt;&lt;/STDIN&gt;</description>
      <pubDate>Tue, 27 Jul 2004 23:23:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting/m-p/3342814#M190983</guid>
      <dc:creator>Ratzie</dc:creator>
      <dc:date>2004-07-27T23:23:15Z</dc:date>
    </item>
    <item>
      <title>Re: Perl scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting/m-p/3342815#M190984</link>
      <description>Hi !&lt;BR /&gt;&lt;BR /&gt;Getting the first 4 chars of a string :&lt;BR /&gt;$&amp;gt; perl&lt;BR /&gt;$String="foobar";&lt;BR /&gt;$SubString=substr($String,0,3);&lt;BR /&gt;print "$SubString\n";&lt;BR /&gt;foo&lt;BR /&gt;&lt;BR /&gt;At end of your script, your files are still open. You do not used close. That's bad :)&lt;BR /&gt;Anyway, if you want to update your file, opening mode isn't good (output). What I would do is to reopen fileC for read and write to another file, adding "'".&lt;BR /&gt;close $fc;&lt;BR /&gt;close $ft;&lt;BR /&gt;close $fo;&lt;BR /&gt;$fc="fileC";&lt;BR /&gt;$fc2="&amp;gt;newfileC";&lt;BR /&gt;open fc or die "fileC : $!";&lt;BR /&gt;open fc2 or die "newfileC : $!";&lt;BR /&gt;while (&lt;FC&gt;) {&lt;BR /&gt;  chomp;&lt;BR /&gt;  ($FirstField,@Rest)=split /,/;&lt;BR /&gt;  print fc2 join ",","'$FirstField'",@Rest;&lt;BR /&gt;}&lt;BR /&gt;close fc;&lt;BR /&gt;close fc2;&lt;BR /&gt;&lt;BR /&gt;To use SQL through perl, you'll have to use DBI and a DBD module. DBI is a common interface to Databases. It will access a DBD module that matches the DB you want (Oracle, MySQL...). Once downloaded the modules (&lt;A href="http://cpan.org)" target="_blank"&gt;http://cpan.org)&lt;/A&gt; and installed, you'll have good usage examples through perldoc.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Fred&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/FC&gt;</description>
      <pubDate>Wed, 28 Jul 2004 03:50:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting/m-p/3342815#M190984</guid>
      <dc:creator>Fred Ruffet</dc:creator>
      <dc:date>2004-07-28T03:50:57Z</dc:date>
    </item>
    <item>
      <title>Re: Perl scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting/m-p/3342816#M190985</link>
      <description>Not an answer to your new question, but there still is some `typo' in the script&lt;BR /&gt;&lt;BR /&gt;print $f join "," =&amp;gt; $acode.$a[0], $bld, $room, $a[1], $a[2], "\n";&lt;BR /&gt;&lt;BR /&gt;print $f join "," =&amp;gt; $acode, $a[0], $bld, $room, $a[1], $a[2], "\n";&lt;BR /&gt;&lt;BR /&gt;Which is *almost* the same. The first line will remove the ',' between $acode and $a[0]&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Wed, 28 Jul 2004 04:01:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting/m-p/3342816#M190985</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2004-07-28T04:01:31Z</dc:date>
    </item>
    <item>
      <title>Re: Perl scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting/m-p/3342817#M190986</link>
      <description>I was hoping someone can explain the errors that I am getting when I attach the rest of the script...&lt;BR /&gt;close $fc;&lt;BR /&gt;close $ft;&lt;BR /&gt;close $fo;&lt;BR /&gt;$fc="fileC";&lt;BR /&gt;$fc2="&amp;gt;newfileC";&lt;BR /&gt;open fc or die "fileC : $!";&lt;BR /&gt;open fc2 or die "newfileC : $!";&lt;BR /&gt;while (&lt;FC&gt;) {&lt;BR /&gt;chomp;&lt;BR /&gt;($FirstField,@Rest)=split /,/;&lt;BR /&gt;print fc2 join ",","'$FirstField'",@Rest;&lt;BR /&gt;}&lt;BR /&gt;close fc;&lt;BR /&gt;close fc2;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;These are the errors I get.&lt;BR /&gt;Unquoted string "fc" may clash with future reserved word at ./test.pl line 31.&lt;BR /&gt;Unquoted string "fc" may clash with future reserved word at ./test.pl line 38.&lt;BR /&gt;Global symbol "$fc2" requires explicit package name at ./test.pl line 30.&lt;BR /&gt;Global symbol "$FirstField" requires explicit package name at ./test.pl line 35.&lt;BR /&gt;Global symbol "@Rest" requires explicit package name at ./test.pl line 35.&lt;BR /&gt;Global symbol "$FirstField" requires explicit package name at ./test.pl line 36.&lt;BR /&gt;Global symbol "@Rest" requires explicit package name at ./test.pl line 36.&lt;BR /&gt;Execution of ./test.pl aborted due to compilation errors.&lt;BR /&gt;&lt;/FC&gt;</description>
      <pubDate>Wed, 28 Jul 2004 19:32:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting/m-p/3342817#M190986</guid>
      <dc:creator>Ratzie</dc:creator>
      <dc:date>2004-07-28T19:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: Perl scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting/m-p/3342818#M190987</link>
      <description>&lt;BR /&gt;&lt;BR /&gt;That code morcel actually works without errors on my box. We'd need more context to understand the line numbers. Attach the whole file if you keep having problems?&lt;BR /&gt;&lt;BR /&gt;I don't like several parts.&lt;BR /&gt;Here are a few comments.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; open fc or die "fileC : $!";&lt;BR /&gt;&lt;BR /&gt;I'd make that: open (fc, $fc) or die "$fc : $!";&lt;BR /&gt;&lt;BR /&gt;This will clearly identify 'fc' as a file handle and remove 'potential confusion with reserved words'.&lt;BR /&gt;And by using the file name variable string in the 'die' text, you will avoid a future dis-connect between name reported and actuall name used.&lt;BR /&gt;&lt;BR /&gt;Ditto for fc2&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; join ",","'$FirstField'",@Rest;&lt;BR /&gt;&lt;BR /&gt;How about some parens to make clear (for yourself!) what is being joined, what is printed. Because you 'chomped' you'll probably need to glue on a new-line.&lt;BR /&gt;So try something like:&lt;BR /&gt;&lt;BR /&gt;print fc2 join (",","'$FirstField'",@Rest)."\n" ;&lt;BR /&gt;&lt;BR /&gt;Good luck!&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Jul 2004 20:14:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting/m-p/3342818#M190987</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-07-28T20:14:12Z</dc:date>
    </item>
    <item>
      <title>Re: Perl scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting/m-p/3342819#M190988</link>
      <description>I am still getting errors...&lt;BR /&gt;I appreciate all the help...&lt;BR /&gt;PS: How do I save the first 4 char in an STDIN?&lt;BR /&gt;print "Enter BLD &amp;gt;";&lt;BR /&gt;chomp (my $bld = &lt;STDIN&gt;);&lt;BR /&gt;&lt;BR /&gt;I need the first 4 char of what they typed.&lt;BR /&gt;&lt;BR /&gt;**********************&lt;BR /&gt;#!/opt/perl/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;&lt;BR /&gt;system ("clear"); #Clear the screen&lt;BR /&gt;my $acode = 204;&lt;BR /&gt;&lt;BR /&gt;print "Enter BLD &amp;gt;";&lt;BR /&gt;chomp (my $bld = &lt;STDIN&gt;);&lt;BR /&gt;print "Enter room&amp;gt;";&lt;BR /&gt;chomp (my $room = &lt;STDIN&gt;);&lt;BR /&gt;&lt;BR /&gt;open my $fc, "&amp;gt;fileC" or die "fileC: $!";&lt;BR /&gt;open my $ft, "&amp;gt;fileT" or die "fileT: $!";&lt;BR /&gt;open my $fo, "&amp;gt;fileO" or die "fileO: $!";&lt;BR /&gt;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;chomp;  # Will remove the leading , or new line&lt;BR /&gt;my @a = split /,/, $_, -1;&lt;BR /&gt;my $f = /TELN/ ? $ft : /CUST/? $fc : $fo;&lt;BR /&gt;print $f join "," =&amp;gt; $acode.$a[0], $bld, $room, $a[1], $a[2], "\n";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;close $fc;&lt;BR /&gt;close $ft;&lt;BR /&gt;close $fo;&lt;BR /&gt;&lt;BR /&gt;$fc="fileC";&lt;BR /&gt;$fc2="&amp;gt;newfileC";&lt;BR /&gt;open (fc, $fc) or die "$fc: $!";&lt;BR /&gt;open (fc2, $fc2) or die "$fc2 : $!";&lt;BR /&gt;while (&lt;FC&gt;) {&lt;BR /&gt;chomp;&lt;BR /&gt;($FirstField,@Rest)=split /,/;&lt;BR /&gt;print fc2 join (",","'$FirstField'",@Rest)."\n";&lt;BR /&gt;}&lt;BR /&gt;close fc;&lt;BR /&gt;close fc2;&lt;BR /&gt;&lt;BR /&gt;****************************&lt;BR /&gt;Unquoted string "fc" may clash with future reserved word at ./test.pl line 32.&lt;BR /&gt;Variable "$fc2" is not imported at ./test.pl line 33.&lt;BR /&gt;Unquoted string "fc" may clash with future reserved word at ./test.pl line 39.&lt;BR /&gt;Global symbol "$fc2" requires explicit package name at ./test.pl line 31.&lt;BR /&gt;Global symbol "$fc2" requires explicit package name at ./test.pl line 33.&lt;BR /&gt;Global symbol "$fc2" requires explicit package name at ./test.pl line 33.&lt;BR /&gt;Global symbol "$FirstField" requires explicit package name at ./test.pl line 36.&lt;BR /&gt;Global symbol "@Rest" requires explicit package name at ./test.pl line 36.&lt;BR /&gt;Global symbol "$FirstField" requires explicit package name at ./test.pl line 37.&lt;BR /&gt;Global symbol "@Rest" requires explicit package name at ./test.pl line 37.&lt;BR /&gt;Execution of ./test.pl aborted due to compilation errors.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; /opt/perl/bin/perl -v&lt;BR /&gt;&lt;BR /&gt;This is perl, v5.8.2 built for PA-RISC1.1-thread-multi&lt;BR /&gt;(with 25 registered patches, see perl -V for more detail)&lt;BR /&gt;&lt;BR /&gt;&lt;/FC&gt;&lt;/STDIN&gt;&lt;/STDIN&gt;&lt;/STDIN&gt;</description>
      <pubDate>Wed, 28 Jul 2004 20:31:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting/m-p/3342819#M190988</guid>
      <dc:creator>Ratzie</dc:creator>
      <dc:date>2004-07-28T20:31:12Z</dc:date>
    </item>
    <item>
      <title>Re: Perl scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting/m-p/3342820#M190989</link>
      <description>&lt;BR /&gt;Ok, the problem now is that you learned to use 'use strict' only half way.&lt;BR /&gt;IF you use it, then you must stricly declare your variables. So you would need to 'my' this $FirstField and @Rest.&lt;BR /&gt;(or just drop the 'use strict' for a qucik test. Did I say that? I did not say that!)&lt;BR /&gt;&lt;BR /&gt;Next, you effectively declared $fc as a file handle in the first open, and then you treat it like a string in the assignment '$fc="fileC";&lt;BR /&gt;&lt;BR /&gt;So you need a fresh variable for that.&lt;BR /&gt;For example (just an example to make it clear, not to follow verbatim):&lt;BR /&gt;&lt;BR /&gt;$fc_name="fileC";&lt;BR /&gt;open (FC_handle, $fc_name) or die "$fc_name: $!";&lt;BR /&gt;while (&lt;FC_HANDLE&gt;) ...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;So much to learn... :-).&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/FC_HANDLE&gt;</description>
      <pubDate>Wed, 28 Jul 2004 21:28:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting/m-p/3342820#M190989</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-07-28T21:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Perl scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting/m-p/3342821#M190990</link>
      <description>first 4 characters of input&lt;BR /&gt;&lt;BR /&gt;chomp (my $bld = &lt;STDIN&gt;);&lt;BR /&gt;length ($bld) &amp;gt; 4 and $bld = substr $bld, 0, 4;&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;$bld =~ s/^(....).*/$1/;&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;length ($bld) &amp;gt; 4 and $bld = join "", (split //, $bld, -1)[0..3];&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;use your imagination ...&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn&lt;/STDIN&gt;</description>
      <pubDate>Thu, 29 Jul 2004 00:24:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting/m-p/3342821#M190990</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2004-07-29T00:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: Perl scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting/m-p/3342822#M190991</link>
      <description>Oh, and as of - I think - 5.8.0 file handles can (and imho should) be used as lexical variables, which makes it much easier to pass around and protect from invalid access&lt;BR /&gt;&lt;BR /&gt;my $fc_name = "fileC";&lt;BR /&gt;open (my $fc, $fc_name) or die "$fc_name: $!";&lt;BR /&gt;while (&amp;lt;$fc&amp;gt;) {&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Thu, 29 Jul 2004 00:28:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting/m-p/3342822#M190991</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2004-07-29T00:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: Perl scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting/m-p/3342823#M190992</link>
      <description>WOW, this perl is not user friendly. I really have to fight to understand it. Thank you for the help.&lt;BR /&gt;I have been able to my script to work with out errors but I can not pull the first column of data out of the file. It put the same thing into the fc2 as fc had. &lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;my $fc_name = "fileC";&lt;BR /&gt;open (my $fc, $fc_name) or die "$fc_name:$!";&lt;BR /&gt;open my $fc2, "&amp;gt;fileC2" or die "fileC2: $!";&lt;BR /&gt;while (&amp;lt;$fc&amp;gt;) {&lt;BR /&gt;chomp;&lt;BR /&gt;my ( $FirstField,@Rest)=split /,/;&lt;BR /&gt;print $fc2 join (",","'$FirstField'",@Rest)."\n";&lt;BR /&gt;}&lt;BR /&gt;close fc;&lt;BR /&gt;close fc2;&lt;BR /&gt;&lt;BR /&gt;This is fc&lt;BR /&gt;'204xxxx345',BUILDING2,ROOM3,00 0 10 14,CUSTOMER HAS&lt;BR /&gt;&lt;BR /&gt;I need this in fc2&lt;BR /&gt;'204xxxx345',&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 29 Jul 2004 12:43:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting/m-p/3342823#M190992</guid>
      <dc:creator>Ratzie</dc:creator>
      <dc:date>2004-07-29T12:43:58Z</dc:date>
    </item>
  </channel>
</rss>

