top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

using join in perl

+1 vote
466 views

I am facing some difficulty using join to display the array elements. Here is the code snippet

[code]use strict;use warnings
my @fruits = qw/apple mango orange banana guava/;
#print '[', join '][', @fruits;#print ']';
print '[', join '][', @fruits, ']';best,
[/code]

[output]
      [apple][mango][orange][banana][guava][]
[/output]

How can I make the output to eliminate the last empty square brackets [] using a single print statement. I used two print statements as shown in the code snippet above (#lines are commented out). Any help is greatly appreciated.

posted Aug 4, 2013 by Jai Prakash

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes
[code] use strict;use warnings;
my @fruits = qw/apple mango orange banana guava/; 
#print '[', join '][', @fruits;#print ']'; 
print '[', join '][', @fruits, ']';
print '[', ( join '][', @fruits ), ']'; 
Please note the placement of the brackets.  best, 
[/code]
[output] 
[apple][mango][orange][banana][guava][]
[/output]
answer Aug 4, 2013 by Salil Agrawal
–1 vote

Limit what join acts on by using parenthesis.

 print '[', join ( '][', @fruits ), ']';

This keeps your closing bracket from being part of the list that join is acting upon.

answer Aug 4, 2013 by Amit Parthsarthi
Similar Questions
+1 vote

I have a roughly 5 GB file where each row is a key, value pair. I would like to use this as a "hashmap" against another large set of file. From searching around, one way to do it would be to turn it into a dbm like DBD and put it into a distributed cache. Another is by joining the data. A third one is putting it into HBase and use it for
lookup.

I'm more familiar with the first approach, so it seems simpler to me. However, I have read that using a distributed cache for files beyond a few megabytes is not recommended because the file is replicated across
all the data nodes. This doesn't seem that bad to me because I just pay this overhead once at the beginning of the job, and then each node gets a copy locally, right? If I were to go with join, would it not increase the workload (more entries) and create the same network congestion issue? And wouldn't going with HBase means making it a bottleneck?

What's the advantage and disadvantage of going for one solution over the others? What if, for example, that "hashmap" needs to be from, say, a 40GB file. How would my option change? At which point would
each option make sense?

0 votes

The following example doesn't compile:

use strict;
use warnings;

sub test {
 print $counter . "n";
}

my $counter = 0;
while($counter < 5) {
 test();
 $counter++;
}

It says "Global symbol "$counter" requires explicit package name ...". When I put the subroutine after the 'while' loop, it works just fine, so what's the problem?

+1 vote

I have a Linux machine and windows machine, I need to run a GUI of Linux machine on the windows machine.
I don't want to use putty or any other software. I have to use any Perl modules to achieve this please help.

+1 vote

I need to access ClearQuest programatically using Perl. I just found ClearQuest OSLC REST API. Client is planning to use ClearQuest web 7.1.1. I read that it comes with OSLC REST API out the box.
Can someone please provide me some examples on how I can access the CQ through Perl using this API.

...