Sponsored Content
Top Forums Shell Programming and Scripting perl array question from going through hash Post 302129125 by hankooknara on Saturday 28th of July 2007 04:39:00 PM
Old 07-28-2007
perl array question from going through hash

suppose my @{$data1{$callid}}; cotains

one two three
three five six
one two three

of random patterns but each item is separated by white space or tab,

Below code extract and get rid of the whitespace perfectly so that it shows now like this

onetwothree
threefivesix
onetwothree

Code:
    39  foreach $callid (sort keys %data1) {
    40       my @fields = @{$data1{$callid}};
    41 
    42       for my $element (@fields) {
    43           $element =~ s/\s+//g;
    44           print "$element";
 
    48       }
    50       print "\n";

but I wanted to do it so that certain length of output woudln't show, such as less than 5, so I thought I could do this,

Code:
    39  foreach $callid (sort keys %data1) {
    40       my @fields = @{$data1{$callid}};
    41  #     print "$callid\n";
    42       for my $element (@fields) {
    43           $element =~ s/\s+//g;
    44            #print "$element";
    45           # next if (length($element) < 15) ;
    46           # print "length($element)";
    47           my @element = join(//,$element);
    48       }
    49       print "@element";
    50       print "\n";

I first did the 45 and 46 but then I realize that I am doing the length on the field(not for the record), so I just try to gather back all the record in array, but I am not having much luck...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

hash,array and perl

Hi,i have a code fragment below. %tag = (); #line 1 $tag{'info'} = $datastring; #line 2 $resp = $ua->request( #$ua is a user agent POST 'http://10.2.3.0' , Content_Type => application/x-www-form-urlencoded Content => #line 3 I am not sure of what the code... (3 Replies)
Discussion started by: new2ss
3 Replies

2. Shell Programming and Scripting

perl hash question

Below is one article I was reading and I don't understand the $seen{$_} = 1 Can someone explain this in easier terms plesae? ____________________________________________________________ We can also take advantage of the uniqueness property of hash keys to filter out duplicates from... (3 Replies)
Discussion started by: hankooknara
3 Replies

3. Shell Programming and Scripting

PERL, push to hash of array problem

$key = "a"; $value = "hello"; %myhash = {} ; push @{ myHash{$key} }, $hello; print $myHash{$key}."\n"; this script prints "hello" but has following error message. Reference found where even-sized list expected at ./test line 5. can any one help me to fix this problem?? (3 Replies)
Discussion started by: bonosungho
3 Replies

4. Shell Programming and Scripting

Array of hash in perl does not work

Hi , I have an input.txt file that i read node: id= c1, class=nb, cx=100, cy=100, r=10 node: id=c2, class=b, cx=150, cy=130, r=10 node: id=c3, class=nb, cx=50, cy=80, r=10 node: id=c4, class=nb, cx=120, cy=200, r=10 i split over , and = to create a global array and then passed it to a... (6 Replies)
Discussion started by: rsanjay
6 Replies

5. Shell Programming and Scripting

perl - need help with 2 arrays to hash or 2d array?

I have 2 arrays: @array1 outputs the following: 1 1 1 2 @array2 outputs the following A B C D (2 Replies)
Discussion started by: streetfighter2
2 Replies

6. Shell Programming and Scripting

perl Can't coerce array into hash at

Hi guys I have this part of a perl script that returns and odd error if ($args{software}) { print " @DISTFILE_GROUPS $output->{distfile_groups}->{ get_rdist_groups}\n"; and the error is Can't coerce array into hash at i've never seed this error before, any ideas thanks... (0 Replies)
Discussion started by: ab52
0 Replies

7. Shell Programming and Scripting

array of hash - perl

How do I get the unique hashes from an array of hashes? @ar1 = ( {a=>1,b=>2}, {c=>3,d=>4},{a=>1,b=>2});I need : @ar2 = ( {a=>1,b=>2}, {c=>3,d=>4});Thanks. (2 Replies)
Discussion started by: shellwell
2 Replies

8. Programming

Perl Array within an hash

Hi All I have been using a curl code to output an hash that looks like this $VAR1 = { 'data'... (5 Replies)
Discussion started by: ab52
5 Replies

9. Shell Programming and Scripting

Perl : Assigning multile hash values to a single array

I know that @food = %fruit; Works. But how do I assign %fruit and %veggies to @food ? (2 Replies)
Discussion started by: popeye
2 Replies

10. Shell Programming and Scripting

Perl hash of hashes anonymous array

Hello experts. I'm having problems with a snippet of code. I was hoping to get help/advice to correct. A file that this script parses has changed to the point where I can no longer use a scalar, it looks as though I need to create an array for a hash of hashes below. The first output of... (1 Reply)
Discussion started by: timj123
1 Replies
ISSPACE(3)						   BSD Library Functions Manual 						ISSPACE(3)

NAME
isspace -- white-space character test LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <ctype.h> int isspace(int c); DESCRIPTION
The isspace() function tests for the standard white-space characters for which isalnum(3) is false. The standard white-space characters are the following: ' ' Space character. f Form feed. New-line. Carriage return. Horizontal tab. v And vertical tab. In the ``C'' locale, isspace() returns true only for the standard white-space characters. RETURN VALUES
The isspace() function returns zero if the character tests false and returns non-zero if the character tests true. SEE ALSO
ctype(3), isalnum(3), isalpha(3), isascii(3), isblank(3), iscntrl(3), isdigit(3), isgraph(3), islower(3), isprint(3), ispunct(3), isupper(3), isxdigit(3), stdio(3), toascii(3), tolower(3), toupper(3), ascii(7) STANDARDS
The isspace() function conforms to ANSI X3.159-1989 (``ANSI C89''). CAVEATS
The argument to isspace() must be EOF or representable as an unsigned char; otherwise, the behavior is undefined. See the CAVEATS section of ctype(3) for more details. BSD
April 17, 2008 BSD
All times are GMT -4. The time now is 08:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy