Perl pos and Solaris cut.

Satalink
Satalink used Ask the Experts™
on
I'm having trouble finding the equivilant of solaris cut in perl

I need to cut a string such as HSTNTXTXCA and grab the state character possition 5 and 6..

solaris equiv:

TID='HSTNTXBGFOMA'
STATE=`echo $TID|cut -c5-6`
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Use substr.  it will return the specifified string that you're looking for.


use strict;

my $TID='HSTNTXBGFOMA';
my $state= substr($TID,  4, 2 );

Commented:
Or use pattern match as this:

my $tt = "ddff33yy";
my ($s) = ($tt =~ /^\w\w\w\w(\w\w)/);
print "S=$s\n";


GT

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial