Perl double splits


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl double splits
# 1  
Old 04-25-2014
Perl double splits

I have a perl script that I was cleaning up, it works very well, but I was wondering if anyone knows of a better way to double split.

Sample file:
Code:
Move_VALIDATE,020212191ABC01,SNSNT---01CAB101A-1-1-4-20
Move_VALIDATE,030323202ABC01,SNSNT01CAB101A-1-1-4-20

Section in script:
Code:
foreach my $line (@file_array){
   my $CHECK_ID = (split /,/, $line) [2];
   my @SPLIT_ID = (split /-/, $CHECK_ID);
   my $FINAL_ID = ($CHECK_ID =~ /---/) ? "$SPLIT_ID[0]---$SPLIT_ID[3]" : "$SPLIT_ID[0]";
   print "$FINAL_ID\n";
}

Output:
Code:
SNSNT---01CAB101A
SNSNT01CAB101A


Last edited by numele; 04-26-2014 at 10:54 AM..
# 2  
Old 04-26-2014
Code:
$line=~/.*,(.*?\w)-\w/; print "$1\n"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Preserve commas inside double quotes (perl)

Hi, I have an input file like this $ cat infile hi,i,"am , sam", y hello ,good, morning abcd, " ef, gh " ,ij no, "good,morning", yes, "good , afternoon" from this file I have to split the fields on basis of comma"," however, I the data present inside double qoutes should be treated as... (3 Replies)
Discussion started by: sam05121988
3 Replies

2. Shell Programming and Scripting

need a perl replacement for this double for loop

hi everybody, can you help me with this? important: it has to be a pure perl code. zz.lis: accessibility arabic archivers astro audio benchmarks . . . "ls accessibility | grep -v Makefile" outputs accerciser at-poke at-spi at-spi-reference (6 Replies)
Discussion started by: pseudocoder
6 Replies

3. Shell Programming and Scripting

awk splits file in to multiple - how to get filenames in variables withing ksh?

Hi all, I'm using awk in a .ksh script to split one file by line prefix into different files (up to 4). The files are named after the prefix in the line, and a sequence no. Is there any way to get the filenames in to variables too? I need _ftpfile1, _ftpfile2, _ftpfile3 and _ftpfile4 which are... (2 Replies)
Discussion started by: spidermike
2 Replies

4. Shell Programming and Scripting

How to substitute the value with in double quotes in perl?

Hi, I have string like this: $str=' DNA OR ("rna AND binding AND protein")'; I just wanted to substitute AND with a blank. How can i do that? I want the output like this: $string= DNA OR ("rna binding protein") (3 Replies)
Discussion started by: vanitham
3 Replies

5. Shell Programming and Scripting

Perl echo with double quotes

I need to echo a string that has double quotes in a Perl script. #!/usr/bin/env perl `echo Rule123 -comment \"blah blah\" >> $filename` I'd like to get below appended to $filename: Rule 123 -comment "blah blah" But instead, the double quotes are lost: Rule 123 -comment blah bah ... (1 Reply)
Discussion started by: slchin
1 Replies

6. Programming

double pow (double x, double y) -- problems

This is the code and I'm wondering why line 14: a = ... and line 16: b = ... is wrong. This is the first time I've tried to use this. Please help me. #include <stdio.h> #include <math.h> // The link and how the double pow is used. // // http://www.nextdawn.nl/c-reference/pow.php //... (2 Replies)
Discussion started by: pwanda
2 Replies

7. Shell Programming and Scripting

problems with double quotes in PERL

I have a cgi script I run through apache2 and I need to have a line that contains double quotes within double quotes. Here's what I need PERL to pass to rrdtool: HRULE:30#BBBB00:"30.0 constant":dashesIt's a little more complicated since I also have variables in the statement which requires... (13 Replies)
Discussion started by: audiophile
13 Replies

8. Shell Programming and Scripting

Float and Double in Perl

HI! What is the notation which correspond to C's doubleandfloatin Perl?? Please tell me. Thanks. Well what I want to do is, for example, calculatingsqrt(2)in two way: float and double. (5 Replies)
Discussion started by: Euler04
5 Replies

9. Shell Programming and Scripting

Displaying double quotes using Perl

Hi Guys, I'm a Perl newbie and was wondering if there's a way of displaying double quotes within double quotes. I'm try to print the contents of the variable to a file by using the system function. Here is an example of my code: #============================== $website = <STDIN>;... (2 Replies)
Discussion started by: kbdesouza
2 Replies

10. Shell Programming and Scripting

PERL, extract value between double quotes

I know this is probably much simplier than I am making but I need some help please. I have a data file that contains a value on the first line between double quotes ("00043"). I need to assign the value between the first set quotes to a variable in my perl script for comparison analysis. Also,... (6 Replies)
Discussion started by: methos
6 Replies
Login or Register to Ask a Question