Basic perl code


 
Thread Tools Search this Thread
Top Forums Programming Basic perl code
# 1  
Old 07-07-2011
Basic perl code

hi,

can anybody explain me the below code. i am new to perl

==========================================

Code:
$o_dups{$1} = 1 if /^\w+\t.{19}\t([^,]+),/;

==========================================


regards,
priyanka

Last edited by pludi; 07-07-2011 at 09:13 AM..
# 2  
Old 07-07-2011
It creates hash element in %o_dups, with the key being extracted from 3rd field in TAB delimited line present in $_. The extracted part is from the start of that field to the first comma.
# 3  
Old 07-07-2011
Code:
$o_dups{$1} = 1 if /^\w+\t.{19}\t([^,]+),/;

man perlre for more info on regexes but a quick breakdown follows
Code:
$o_dups{$1}=1 # set the value in the o_dups hash for the match capture ($1) to true 
 if /^\w+\t.{19}\t([^,]+),/;#if the regex matches

The regex itself breaks down as:
Code:
/^ # beinning of line
\w+# one or more "word" characters, (ie. alphanumeric + "_")
 \t # a litteral tab
.{19} # any 19 characters
\t # a literal tab again
([^,]+) # A series of non "," chars in brackets so capture this as the first capture ($1 above)
,#followed by a comma
/ #End match

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Basic Question on perl use POSIX [SOLVED]

Hi guys, I think this is a basic question. I'm not very familiar with this. I'm trying to round a number up and round a number down. From what I have read this can be done using POSIX. I have tried to to use this, but i'm getting errors: sub findGridBounds($$$%) { use POSIX; ... (0 Replies)
Discussion started by: WongSifu
0 Replies

2. Shell Programming and Scripting

Perl basic code 3

Hi , I am having csv contains data 2011-08-23 11:11:00.074+0000: Info: Duplicate Order is not processed,Original Order Tuple ($category, $type) = split(',', $_ , 2); what is the split function work here?? Thanks Please start using code tags, thanks. (5 Replies)
Discussion started by: pspriyanka
5 Replies

3. Shell Programming and Scripting

perl basic code

Hi, foreach $cat (sort{$cats{$b} <=> $cats{$a}} keys %cats) can anyone explain me above code?? i am new to perl Thanks (1 Reply)
Discussion started by: pspriyanka
1 Replies

4. Shell Programming and Scripting

perl basic code

Hi, can anybody explain me below code $cats{$category}++ Thanks (2 Replies)
Discussion started by: pspriyanka
2 Replies

5. Programming

Basic perl code- Date format

Hi friends, Please see the below code carefully. ======================================================= # Get batch date and Ord range open OR,$ARGV; while (<OR>) { # find the batch date next if length $_ < 3; # BLANK LINE # last if $. > 120; # sample should be good enough... (2 Replies)
Discussion started by: pspriyanka
2 Replies

6. Shell Programming and Scripting

Basic Perl - pass by ref

#!/usr/bin/perl sub addToHash{ my(%hash) = @_; $hash{ 'A' } = 'value'; $hash{ 'B' } = 'value'; $hash{ 'C' } = 'value'; print("Hashmap size is " .keys(%hash) . "\n"); } my %myhash = (); addToHash(\%myhash); print("Hashmap size is " .keys(%myhash) . "\n"); I want this... (6 Replies)
Discussion started by: chrisjones
6 Replies

7. Shell Programming and Scripting

perl basic multiple pattern matching

Hi everyone, and thank you for your help with this. I am VERY new with perl so all of your help is appreciated. I have tried google but as I don't know the proper terms to search for and could be daunting for a newbie scripter... I know this is very easy for most of you! Thanks! I have a... (4 Replies)
Discussion started by: sinusoid
4 Replies

8. Programming

Problems using Perl DBI to edit database entries - basic stuff

Hello. I am taking a Perl class in college and we've briefly covered SQL and moved on. We have a term project and we can do whatever we want. My project will rely strongly on an SQL Database so I am trying to learn as much about Perl DBI as I can to get things up and going. I am basically... (1 Reply)
Discussion started by: Dave247
1 Replies

9. UNIX for Dummies Questions & Answers

basic perl question

Hi, I was jus goin through a ebook on perl....it says u get binary installation for both unix and windows.....doesnt perl come already bundeled with unix ?cause i never installed any perl from binary........but i am able to execute perl programs...... Thanks and Regards Vivek.S (1 Reply)
Discussion started by: vivekshankar
1 Replies
Login or Register to Ask a Question