Sponsored Content
Top Forums Shell Programming and Scripting Perl Array Variables to be returned to main Post 302330377 by Raynon on Wednesday 1st of July 2009 04:26:32 AM
Old 07-01-2009
Hi prasperl,

May i know if the below code is added , will it set all the rest of the base array index to 1 or does it just apply to the particular array @Marks only ?

Code:
$[ = 1;

Another question is that my "reports_${counting}_${_[0]}.txt" file has the below contents, however if i put the index to be the below in red, i would NOT be able to capture the correct $lotsuffix variable ? Why is this so ?

Code:
LOTSUFFIX1= AAAAA
LOTSUFFIX2= BBBBBB
LOTSUFFIX3= NIL
LOTSUFFIX4= NIL
LOTSUFFIX5= NIL
LOTSUFFIX6= NIL
LOTSUFFIX7= NIL
LOTSUFFIX8= NIL
LOTSUFFIX9= NIL
LOTSUFFIX10= NIL

DATE1= 29-Jun
DATE2= 29-Jun
DATE3=
DATE4=
DATE5=
DATE6=
DATE7=
DATE8=
DATE9=
DATE10=

Code:
my @Fld = split(' ', $line );
if ( $Fld[0] eq 'LOTSUFFIX=' ) {
          $lotsuffix[$counting] = $Fld[1];
          print "$lotsuffix[$counting]\n";
}


Last edited by Raynon; 07-01-2009 at 05:41 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl: storing regex in array variables trouble

hi this is an example of code: use strict; use warnings; open FILE, "/tmp/result_2"; my $regex="\\ Starting program ver. (.*)"; my $res="Program started, version <$1> - OK.\n"; while (<FILE>) { if ($_ =~ /($regex)/) { print "$res"; } } close FILE; This finds $regex and print... (3 Replies)
Discussion started by: xist
3 Replies

2. Shell Programming and Scripting

'who' command -- getting data returned into variables (in bash)

Anyone know how to get the data out of the "who" command? I'm still in lukewarm pursuit of creating an OS X-like welcome message at the start of any Terminal session, sans having to use either bash login or calling up ssh. My trials & errors and surfing around have narrowed it down for me... (1 Reply)
Discussion started by: SilversleevesX
1 Replies

3. Shell Programming and Scripting

perl, put one array into many array when field is equal to sth

Hi Everyone, #!/usr/bin/perl use strict; use warnings; my @test=("a;b;qqq;c;d","a;b;ggg;c;d","a;b;qqq;c;d"); would like to split the @test array into two array: @test1=(("a;b;qqq;c;d","a;b;qqq;c;d"); and @test2=("a;b;ggg;c;d"); means search for 3rd filed. Thanks find the... (0 Replies)
Discussion started by: jimmy_y
0 Replies

4. Shell Programming and Scripting

Perl, searching multiple files and printing returned line to new file

I am trying to find a way to utilise the full potential of my cpu cores and memory on my windows machine. Now, I am quite familiar with grep, however, running a Unix based OS is not an option right now. Unfortunately, the 32 bit grep for windows that I am running, I cannot run multiple... (1 Reply)
Discussion started by: Moloch
1 Replies

5. Shell Programming and Scripting

How to get the main node name in xml using perl?

Hi, I am having an conf file like this: <Main> <NODE> <NODENAME>FRUITS</NODENAME> <NAME>APPLE</NAME> <COLOUR>RED</COLOUR> <NODE> <IsWrapper/> <NODENAME>SEASONAL</NODENAME> <NODE> <NAME>MANGO</NAME> <COLOUR>GREEN</COLOUR> </NODE> </NODE>... (4 Replies)
Discussion started by: vanitham
4 Replies

6. Shell Programming and Scripting

Help in separating variables declared in the main function

Hi! I've a C program as shown below.. The line numbers and the statements of the program are separated by a space.. 1 #include<stdio.h> 2 char a,b,c; 3 float x,y,z; 4 int main() 5 { 6 int d,e,f; 7 // further declarations 8 // further declarations 9 /* body*/ 10 } 11 void fun1() 12... (1 Reply)
Discussion started by: abk07
1 Replies

7. Shell Programming and Scripting

PERL : Read an array and write to another array with intial string pattern checks

I have an array and two variables as below, I need to check if $datevar is present in $filename. If so, i need to replace $filename with the values in the array. I need the output inside an ARRAY How can this be done. Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies

8. UNIX for Dummies Questions & Answers

[ksh93+] Array fed by function is empty when used in main.

I feel that i am missing something obvious but i can't find what is wrong. I have a script that is launching some functions with "&" and each call is feeding the array with a value. When all calls are finished I just want to retrieve the values of that array. It is looking like that : ... (5 Replies)
Discussion started by: bibou25
5 Replies

9. Shell Programming and Scripting

Perl: How to avoid warnings for superfluous values returned?

Hi all, a question for the Perl knowledgeable: I have use warnings; enabled. I use something like: ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); In the further code I only work with some of the returned variables, as the others I have no need for. Though the... (1 Reply)
Discussion started by: zaxxon
1 Replies

10. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies
Perl::Critic::Policy::Variables::RequireNegativeIndices(User Contributed Perl DocumentatPerl::Critic::Policy::Variables::RequireNegativeIndices(3)

NAME
Perl::Critic::Policy::Variables::RequireNegativeIndices - Negative array index should be used. AFFILIATION
This Policy is part of the core Perl::Critic distribution. DESCRIPTION
Perl treats a negative array subscript as an offset from the end. Given this, the preferred way to get the last element is $x[-1], not $x[$#x] or $x[@x-1], and the preferred way to get the next-to-last is $x[-2], not "$x[$#x-1" or $x[@x-2]. The biggest argument against the non-preferred forms is that their semantics change when the computed index becomes negative. If @x contains at least two elements, $x[$#x-1] and $x[@x-2] are equivalent to $x[-2]. But if it contains a single element, $x[$#x-1] and $x[@x-2] are both equivalent to $x[-1]. Simply put, the preferred form is more likely to do what you actually want. As Conway points out, the preferred forms also perform better, are more readable, and are easier to maintain. This policy notices all of the simple forms of the above problem, but does not recognize any of these more complex examples: $some->[$data_structure]->[$#{$some->[$data_structure]} -1]; my $ref = @arr; $ref->[$#arr]; CONFIGURATION
This Policy is not configurable except for the standard options. AUTHOR
Chris Dolan <cdolan@cpan.org> COPYRIGHT
Copyright (c) 2006-2011 Chris Dolan. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.16.3 2014-06-09 Perl::Critic::Policy::Variables::RequireNegativeIndices(3)
All times are GMT -4. The time now is 07:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy