Sponsored Content
Top Forums Shell Programming and Scripting Perl Array Variables to be returned to main Post 302330360 by prasperl on Wednesday 1st of July 2009 02:56:12 AM
Old 07-01-2009
If you still want to keep the base index as 1,use this command,

$[=1;

sample code:
@Marks = (10,11,2007);
print @Marks[0],@Marks[1],@Marks[2];
$[=1;
print @Marks[1],@Marks[2],@Marks[3];


 

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
MouseX::NativeTraits::ArrayRef(3pm)			User Contributed Perl Documentation		       MouseX::NativeTraits::ArrayRef(3pm)

NAME
MouseX::NativeTraits::ArrayRef - Helper trait for ArrayRef attributes SYNOPSIS
package Stuff; use Mouse; has 'options' => ( traits => ['Array'], is => 'ro', isa => 'ArrayRef[Str]', default => sub { [] }, handles => { all_options => 'elements', add_option => 'push', map_options => 'map', filter_options => 'grep', find_option => 'first', get_option => 'get', join_options => 'join', count_options => 'count', has_options => 'count', has_no_options => 'is_empty', sorted_options => 'sort', }, ); DESCRIPTION
This module provides an Array attribute which provides a number of array operations. PROVIDED METHODS
These methods are implemented in MouseX::NativeTraits::MethodProvider::ArrayRef. count Returns the number of elements in the array. $stuff = Stuff->new; $stuff->options(["foo", "bar", "baz", "boo"]); my $count = $stuff->count_options; print "$count "; # prints 4 is_empty Returns a boolean value that is true when the array has no elements. $stuff->has_no_options ? die "No options! " : print "Good boy. "; elements Returns all of the elements of the array. my @option = $stuff->all_options; print "@options "; # prints "foo bar baz boo" get($index) Returns an element of the array by its index. You can also use negative index numbers, just as with Perl's core array handling. my $option = $stuff->get_option(1); print "$option "; # prints "bar" pop push($value1, $value2, value3 ...) shift unshift($value1, $value2, value3 ...) splice($offset, $length, @values) These methods are all equivalent to the Perl core functions of the same name. first( sub { ... } ) This method returns the first item matching item in the array, just like List::Util's "first" function. The matching is done with a subroutine reference you pass to this method. The reference will be called against each element in the array until one matches or all elements have been checked. my $found = $stuff->find_option( sub { /^b/ } ); print "$found "; # prints "bar" any( sub { ... } ) This method returns true if any item in the array meets the criterion given through the subroutine, otherwise returns false. It sets $_ for each item in the array. grep( sub { ... } ) This method returns every element matching a given criteria, just like Perl's core "grep" function. This method requires a subroutine which implements the matching logic. my @found = $stuff->filter_options( sub { /^b/ } ); print "@found "; # prints "bar baz boo" map( sub { ... } ) This method transforms every element in the array and returns a new array, just like Perl's core "map" function. This method requires a subroutine which implements the transformation. my @mod_options = $stuff->map_options( sub { $_ . "-tag" } ); print "@mod_options "; # prints "foo-tag bar-tag baz-tag boo-tag" apply( sub { ... } ) This method also transform every element in the array and returns a new array, just like List::MoreUtils's "apply" function.his is similar to "map", but does not modify the element of the array. reduce( sub { ... } ) This method condenses an array into a single value, by passing a function the value so far and the next value in the array, just like List::Util's "reduce" function. The reducing is done with a subroutine reference you pass to this method. my $found = $stuff->reduce_options( sub { $_[0] . $_[1] } ); print "$found "; # prints "foobarbazboo" sort( &compare ) Returns the array in sorted order. You can provide an optional subroutine reference to sort with (as you can with Perl's core "sort" function). However, instead of using $a and $b, you will need to use $_[0] and $_[1] instead. # ascending ASCIIbetical my @sorted = $stuff->sort_options(); # Descending alphabetical order my @sorted_options = $stuff->sort_options( sub { lc $_[1] cmp lc $_[0] } ); print "@sorted_options "; # prints "foo boo baz bar" sort_in_place( &compare ) Sorts the array in place, modifying the value of the attribute. You can provide an optional subroutine reference to sort with (as you can with Perl's core "sort" function). However, instead of using $a and $b, you will need to use $_[0] and $_[1] instead. sort_by( &by, &compare ) Returns the array in sorted order, applying &by function to each item. This is equivalent to "sort(sub{ by($_[0]) cmp by($_[1]) })", but implemented effectively. Currently (as of Moose 0.98) this is a Mouse specific method. sort_in_place_by( &by, &compare ) Sorts the array, applying &by function to each item, modifying the value of the attribute. This is equivalent to "sort_in_place(sub{ by($_[0]) cmp by($_[1]) })", but implemented effectively. Currently (as of Moose 0.98) this is a Mouse specific method. shuffle Returns the array, with indices in random order, like "shuffle" from List::Util. uniq Returns the array, with all duplicate elements removed, like "uniq" from List::MoreUtils. join($str) Joins every element of the array using the separator given as argument, just like Perl's core "join" function. my $joined = $stuff->join_options( ':' ); print "$joined "; # prints "foo:bar:baz:boo" set($index, $value) Given an index and a value, sets the specified array element's value. delete($index) Removes the element at the given index from the array. insert($index, $value) Inserts a new element into the array at the given index. clear Empties the entire array, like "@array = ()". accessor This method provides a get/set accessor for the array, based on array indexes. If passed one argument, it returns the value at the specified index. If passed two arguments, it sets the value of the specified index. for_each(sub{ ... }) This method calls the given subroutine with each element of the array, like Perl's core "foreach" statement. Currently (as of Moose 0.98) this is a Mouse specific method. for_each_pair( sub{ ... } ) This method calls the given subroutine with each two element of the array, as if the array is a list of pairs. Currently (as of Moose 0.98) this is a Mouse specific method. METHODS
meta method_provider_class helper_type SEE ALSO
MouseX::NativeTraits perl v5.14.2 2011-12-04 MouseX::NativeTraits::ArrayRef(3pm)
All times are GMT -4. The time now is 01:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy