Solved

perl split

Posted on 2013-01-07
2
392 Views
Last Modified: 2013-01-07
split (/\t+/, $line);  # this code split on tabs (\t), but what does the + after the \t do?
0
Comment
Question by:rgbcof
2 Comments
 
LVL 31

Accepted Solution

by:
farzanj earned 250 total points
ID: 38753627
+ means one or more tabs.  So more than one tabs together will also be treated like one tab.
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 250 total points
ID: 38753631
see
perldoc perlre
or
perl -mYAPE::Regex::Explain -e "print YAPE::Regex::Explain->new(qr/\t+/)->explain"
The regular expression:

(?-imsx:\t+)

matches as follows:
 
NODE                     EXPLANATION
----------------------------------------------------------------------
(?-imsx:                 group, but do not capture (case-sensitive)
                         (with ^ and $ matching normally) (with . not
                         matching \n) (matching whitespace and #
                         normally):
----------------------------------------------------------------------
  \t+                      '\t' (tab) (1 or more times (matching the
                           most amount possible))
----------------------------------------------------------------------
)                        end of grouping
----------------------------------------------------------------------
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
perl script help 12 104
perl split by | 2 90
perl script to search for files containing text 3 73
Regular Expression question to filter with negation. 6 89
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now