Sponsored Content
Top Forums Shell Programming and Scripting [Perl] split on : but with extra challenge Post 302968885 by ejdv on Tuesday 15th of March 2016 01:18:01 PM
Old 03-15-2016
[Perl] split on : but with extra challenge

Hi,

I am looking for a little bit more advanced split.

Code:

Code:
#!/usr/bin/perl -w #-d
use strict;

my $Line = "value1:{value2a:value2b}:value3:{}:value5:{value6a:value6b}";

my @LineAttributes = split (/:/, $Line);

my $TotalLineAttributes = scalar @LineAttributes;

print "Line: $Line\n\n";
print "Total attributes: $TotalLineAttributes\n\n";

foreach my $Attribute (@LineAttributes) {
  print "Attribute: $Attribute\n";
}

Result:

Code:
Line: value1:{value2a:value2b}:value3:{}:value5:{value6a:value6b}

Total attributes: 8

Attribute: value1
Attribute: {value2a
Attribute: value2b}
Attribute: value3
Attribute: {}
Attribute: value5
Attribute: {value6a
Attribute: value6b}

I would like to see 6 as result.
The length of the line and the number of values my vary.

Any ideas?

Greetings,

Erik
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl split function

$mystring = "name:blk:house::"; print "$mystring\n"; @s_format = split(/:/, $mystring); for ($i=0; $i <= $#s_format; $i++) { print "index is $i,field is $s_format"; print "\n"; } $size = $#s_format + 1; print "total size of array is $size\n"; i am expecting my size to be 5, why is it... (5 Replies)
Discussion started by: new2ss
5 Replies

2. Shell Programming and Scripting

Use split function in perl

Hello, if i have file like this: 010000890306932455804 05306977653873 0520080417010520ISMS SMT ZZZZZZZZZZZZZOC30693599000 30971360000 ZZZZZZZZZZZZZZZZZZZZ202011302942311 010000890306946317387 05306977313623 0520080417010520ISMS SMT ZZZZZZZZZZZZZOC306942190000 30971360000... (5 Replies)
Discussion started by: chriss_58
5 Replies

3. Shell Programming and Scripting

PERL cgi script... extra character driving me crazy

I'm using a PERL cgi script that uses rrdtool to make graphs. I can't get the syntax correct to use a degree sign (alt+0176 like this °) and also using a variable. If I use single quotes, I can't call the variable. If I use double quotes, there is an extra symbol (Â) before the ° which goes... (2 Replies)
Discussion started by: audiophile
2 Replies

4. Shell Programming and Scripting

Perl split question

hi, I have a seemingly really stupid question, but here goes! What do you enter into split delimiter to seperate something like this "December 12, 1995" and get December 12 1995 ? thanks (5 Replies)
Discussion started by: ade214
5 Replies

5. Homework & Coursework Questions

PERL split function

Hi... I have a question regarding the split function in PERL. I have a very huge csv file (more than 80 million records). I need to extract a particular position(eg : 50th position) of each line from the csv file. I tried using split function. But I realized split takes a very long time. Also... (0 Replies)
Discussion started by: castle
0 Replies

6. Shell Programming and Scripting

Perl split, but ignoring extra delimiters

Hi all, I'm going bonkers trying to figure something out that is probably simple for most of you. I have a choice between getting therapy for this or coming here to ask for help. I chose the latter. :D What I'm trying to do is perform a split on a line but only one split. For example, let's... (4 Replies)
Discussion started by: goober
4 Replies

7. Shell Programming and Scripting

Regular Expression in Perl - very challenge

Hi expert, As we know in regular expression, means neither a nor b. Now the question is how to consider <ab> as a whole part or somehow a single char. Something like which is meaning neither ( nor a nor b nor ). Or do we have another way for this? The real requirement is as below: ... (2 Replies)
Discussion started by: summer_cherry
2 Replies

8. Shell Programming and Scripting

Split the string in perl

Hi All, How to split the string KAR_Celltick_Ban_GSMGW3 and want to pickup the third filed. Sometime the string may be "KAR_Celltick_Ban" like this Thanks in advance (1 Reply)
Discussion started by: sujit_kashyap
1 Replies

9. UNIX for Advanced & Expert Users

Interesting awk/Perl/sed parsing challenge

I have a log with entries like: out/target/product/imx53_smd/obj/STATIC_LIBRARIES/libwebcore_intermediates/Source/WebCore/bindings/V8HTMLVideoElement.cpp : target thumb C++: libwebcore <=... (8 Replies)
Discussion started by: glev2005
8 Replies

10. Shell Programming and Scripting

Perl split and array

Hello, I have the following code: while ($line = <fd_in>) { 126 $line = " " . $line ; 127 print "our_line:$line\n"; 128 @list = split (/\s+/, $line) ; 129 print "after_split:@list\n"; 130 print "$list\t$list\t$list\t$list\t$list\t$list$list\t\n"; 131 $len =... (2 Replies)
Discussion started by: Zam_1234
2 Replies
PPI::Token::Attribute(3)				User Contributed Perl Documentation				  PPI::Token::Attribute(3)

NAME
PPI::Token::Attribute - A token for a subroutine attribute INHERITANCE
PPI::Token::Attribute isa PPI::Token isa PPI::Element DESCRIPTION
In Perl, attributes are a relatively recent addition to the language. Given the code " sub foo : bar(something) {} ", the "bar(something)" part is the attribute. A "PPI::Token::Attribute" token represents the entire of the attribute, as the braces and its contents are not parsed into the tree, and are treated by Perl (and thus by us) as a single string. METHODS
This class provides some additional methods beyond those provided by its PPI::Token and PPI::Element parent classes. Got any ideas for methods? Submit a report to rt.cpan.org! identifier The "identifier" attribute returns the identifier part of the attribute. That is, for the attribute "foo(bar)", the "identifier" method would return "foo". parameters The "parameters" method returns the parameter strong for the attribute. That is, for the attribute "foo(bar)", the "parameters" method would return "bar". Returns the parameters as a string (including the null string '' for the case of an attribute such as "foo()". Returns "undef" if the attribute does not have parameters. SUPPORT
See the support section in the main module. AUTHOR
Adam Kennedy <adamk@cpan.org> COPYRIGHT
Copyright 2001 - 2011 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.16.2 2011-02-25 PPI::Token::Attribute(3)
All times are GMT -4. The time now is 09:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy