Sponsored Content
Top Forums Shell Programming and Scripting Perl: array name tha contains contents of a variable Post 302736549 by birei on Tuesday 27th of November 2012 12:46:17 PM
Old 11-27-2012
Hi hcclnoodles,

I don't know why you could want to do that. I'm sure it is a red flag in your program. Said that, here there is one way:
Code:
$ cat script.pl                                                                                                                                                                                                            
#!/usr/bin/env perl                                                                                                                                                                                                                          
                                                                                                                                                                                                                                             
use strict;                                                                                                                                                                                                                                  
use warnings;                                                                                                                                                                                                                                
                                                                                                                                                                                                                                             
{
        my $counter = 0;

        my $name = 'array' . $counter;

        no strict;
        no warnings;
        @{$name} = qw<some stuff>;

        printf qq|%s\n|, join q|,|, @array0;
}
$ perl script.pl
some,stuff

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Display the contents of an array

Hi i have just registered So i am at university studying forensic computing and we have to learn c++ i have never done anything with c++ before and i am abit stuck i need to create a programme to display the contents of an array of characters forwards and in reverse Can anyone help me... (1 Reply)
Discussion started by: RossMc
1 Replies

2. Shell Programming and Scripting

PERL - copy fiel contents to array then compare against other file

Basically to illuminate i want to take a file with mutliple lines, C:\searching4theseletters.txt a b c Read this into an array @ARRAY and then use this to compare against another file C:\inputletters.txt b o a c n a (9 Replies)
Discussion started by: bradleykins
9 Replies

3. Shell Programming and Scripting

How to match all array contents and display all highest matched sentences in perl?

Hi, I have an array with 3 words in it and i have to match all the array contents and display the exact matched sentence i.e all 3 words should match with the sentence. Here are sentences. $arr1="Our data suggests that epithelial shape and growth control are unequally affected depending... (5 Replies)
Discussion started by: vanitham
5 Replies

4. Shell Programming and Scripting

Perl help: Creating a multidimensional array of subdirectories and its contents

I'm currently working with dozens of FASTA files, and I'm tired of having to manually change the filename in my Perl script. I'm trying to write a simple Perl script that'll create a 2-dimensional array containing the name of the folders and its contents. For example, I would like the output... (6 Replies)
Discussion started by: shwang3
6 Replies

5. Shell Programming and Scripting

perl launch threads in an array variable?

Im having a problem launching multiple sub routines as threads. My script seems to stop when the first thread is launched. Im condensing the code for simplification here: #!/usr/bin/perl -w use strict; use threads; srand; my ($cnt,$line,$iprange_rand); my... (2 Replies)
Discussion started by: trey85stang
2 Replies

6. Shell Programming and Scripting

Perl question - How do I print contents of an array on a single line?

I have the following code: print @testarray; which returns: 8 8 8 9 How do I return the array like this: The output is: 8, 8, 8, 9 (5 Replies)
Discussion started by: streetfighter2
5 Replies

7. Shell Programming and Scripting

[Perl] Split lines into array - variable line items - variable no of lines.

Hi, I have the following lines that I would like to see in an array for easy comparisons and printing: Example 1: field1,field2,field3,field4,field5 value1,value2,value3,value4,value5Example 2: field1,field3,field4,field2,field5,field6,field7... (7 Replies)
Discussion started by: ejdv
7 Replies

8. Shell Programming and Scripting

Folder contents getting appended as strings while redirecting file contents to a variable

Hi one of the output of the command is as below # sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/' Resource List : <br> *************************** 1. row ***************************<br> ... (2 Replies)
Discussion started by: vivek d r
2 Replies

9. Shell Programming and Scripting

Display array contents on a new line

ksh eg arrayname=(1 2 3 4 5) I'm trying to display the individual contents of an array on a new line without using a loop, using one line of code. output 1 2 3 4 5 (3 Replies)
Discussion started by: squrcles
3 Replies

10. News, Links, Events and Announcements

GCC for tha AMIGA...

Hi guys... For the AMIGA fans out there... Not sure if this is the right forum but someone has done a successful working port of gcc for the classic AMIGA A1200. It contains a very large subset of *NIX commands and now AMIGA fanatics like me can include another platform, within the... (0 Replies)
Discussion started by: wisecracker
0 Replies
CounterFile(3pm)					User Contributed Perl Documentation					  CounterFile(3pm)

NAME
File::CounterFile - Persistent counter class SYNOPSIS
use File::CounterFile; $c = File::CounterFile->new("COUNTER", "aa00"); $id = $c->inc; open(F, ">F$id"); DESCRIPTION
This module implements a persistent counter class. Each counter is represented by a separate file in the file system. File locking is applied, so multiple processes can attempt to access a counter simultaneously without risk of counter destruction. You give the file name as the first parameter to the object constructor ("new"). The file is created if it does not exist. If the file name does not start with "/" or ".", then it is interpreted as a file relative to $File::CounterFile::DEFAULT_DIR. The default value for this variable is initialized from the environment variable "TMPDIR", or /usr/tmp if no environment variable is defined. You may want to assign a different value to this variable before creating counters. If you pass a second parameter to the constructor, it sets the initial value for a new counter. This parameter only takes effect when the file is created (i.e. it does not exist before the call). When you call the "inc()" method, you increment the counter value by one. When you call "dec()", the counter value is decremented. In both cases the new value is returned. The "dec()" method only works for numerical counters (digits only). You can peek at the value of the counter (without incrementing it) by using the "value()" method. The counter can be locked and unlocked with the "lock()" and "unlock()" methods. Incrementing and value retrieval are faster when the counter is locked, because we do not have to update the counter file all the time. You can query whether the counter is locked with the "locked()" method. There is also an operator overloading interface to the File::CounterFile object. This means that you can use the "++" operator for incrementing and the "--" operator for decrementing the counter, and you can interpolate counters directly into strings. COPYRIGHT
Copyright (c) 1995-1998,2002,2003 Gisle Aas. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. AUTHOR
Gisle Aas <gisle@aas.no> perl v5.10.0 2004-01-23 CounterFile(3pm)
All times are GMT -4. The time now is 11:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy