doubt in substring

------_=_NextPart_001_01CBB2DA.20A07483
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hi All



I have a string as; $str =3D "the cat sat on the mat" .



How the following command works substr($str , 4, -4) on the string ?
What should be the output?







Thanks

Sunita


------_=_NextPart_001_01CBB2DA.20A07483--
Sunita Rani Pradhan [ Do, 13 Januar 2011 05:27 ] [ ID #2053115 ]

Re: doubt in substring

--e0cb4e43d1af83a3330499b2db07
Content-Type: text/plain; charset=ISO-8859-1

the output will be

cat sat on the

all the characters in the string $str except four characters from the left
and right will be displayed...

Regards
Ashwin Thayyullathil Surendran



On Thu, Jan 13, 2011 at 9:57 AM, Sunita Rani Pradhan <
Sunita.Pradhan [at] altair.com> wrote:

> Hi All
>
>
>
> I have a string as; $str = "the cat sat on the mat" .
>
>
>
> How the following command works substr($str , 4, -4) on the string ?
> What should be the output?
>
>
>
>
>
>
>
> Thanks
>
> Sunita
>
>

--e0cb4e43d1af83a3330499b2db07--
ashwin ts [ Do, 13 Januar 2011 05:35 ] [ ID #2053116 ]

Re: doubt in substring

On Jan 12, 8:27=A0pm, Sunita.Prad... [at] altair.com ("Sunita Rani Pradhan")
wrote:
> Hi All
>
> =A0 =A0 =A0 =A0 =A0 =A0 I have a string as; $str =3D =A0"the cat sat on t=
he mat" .
>
> How the following command works substr($str , 4, -4) =A0on the string ?
> What should be the output?
>

See: perldoc -f substr

Check the docs first for explanations and examples of any
Perl builtin function.

--
Charles DeRykus


--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
derykus [ Do, 13 Januar 2011 08:23 ] [ ID #2053121 ]

Re: doubt in substring

On 11-01-12 11:27 PM, Sunita Rani Pradhan wrote:
> I have a string as; $str = "the cat sat on the mat" .
>
>
>
> How the following command works substr($str , 4, -4) on the string ?
> What should be the output?

TITS (Try It To See)

perl -le '$str = "the cat sat on the mat";print substr( $str, 4, -4 )'


--
Just my 0.00000002 million dollars worth,
Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software: Fail early & often.

Eliminate software piracy: use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Shawn H Corey [ Do, 13 Januar 2011 15:16 ] [ ID #2053134 ]

Re: doubt in substring

--001636c5b764583bd10499ddd5e5
Content-Type: text/plain; charset=ISO-8859-1

Setting environment for using XAMPP for Windows.

rmicro [at] RMICRO-PC C:\Program Files\xampp
# perl -le '$str = "the cat sat on the mat";print substr( $str, 4, -4 )'
Can't find string terminator "'" anywhere before EOF at -e line 1.

rmicro [at] RMICRO-PC C:\Program Files\xampp
#

It failed to work for me. Why?



rmicro [at] RMICRO-PC C:\Program Files\xampp
# perl -v

This is perl, v5.10.1 (*) built for MSWin32-x86-multi-thread

Copyright 1987-2009, Larry Wall

Perl may be copied only under the terms of either the Artistic License or
the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.




On Thu, Jan 13, 2011 at 3:16 PM, Shawn H Corey <shawnhcorey [at] gmail.com>wrote:

> On 11-01-12 11:27 PM, Sunita Rani Pradhan wrote:
>
>> I have a string as; $str = "the cat sat on the mat" .
>>
>>
>>
>> How the following command works substr($str , 4, -4) on the string ?
>> What should be the output?
>>
>
> TITS (Try It To See)
>
> perl -le '$str = "the cat sat on the mat";print substr( $str, 4, -4 )'
>
>
> --
> Just my 0.00000002 million dollars worth,
> Shawn
>
> Confusion is the first step of understanding.
>
> Programming is as much about organization and communication
> as it is about coding.
>
> The secret to great software: Fail early & often.
>
> Eliminate software piracy: use only FLOSS.
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
> For additional commands, e-mail: beginners-help [at] perl.org
> http://learn.perl.org/
>
>
>


--
*Satajanus Nig. Ltd


*

--001636c5b764583bd10499ddd5e5--
Emeka [ Sa, 15 Januar 2011 08:52 ] [ ID #2053235 ]

Re: doubt in substring

On 15 January 2011 07:52, Emeka <emekamicro [at] gmail.com> wrote:

> # perl -le '$str = "the cat sat on the mat";print substr( $str, 4, -4 )'
> Can't find string terminator "'" anywhere before EOF at -e line 1.
>
> rmicro [at] RMICRO-PC C:\Program Files\xampp
> #
>
> It failed to work for me. Why?

Because you can't use single quotes for the script-string in Windows
cmd.exe. If you must work in the command line, then you can either
escape all your double quotes within the string or use
qq~double-quoted string~ , where "~" can be any ascii character that
is not in the string itself.

perl -le "$str = qq~the cat sat on the mat~; print substr( $str, 4, -4 )"

If I were beginning with Perl, I certainly would not practise in the
console but get an editor, such as SciTE

<http://www.scintilla.org/SciTE.html>

and run the scripts from the editor (using F5) in the case of SciTE.

JD

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
John Delacour [ Sa, 15 Januar 2011 15:04 ] [ ID #2053238 ]

Re: doubt in substring

--001636c5a30eb6f90b0499e5a711
Content-Type: text/plain; charset=ISO-8859-1

*If I were beginning with Perl, I certainly would not practise in the
console but get an editor, such as SciTE*
Yes, I am.

On Sat, Jan 15, 2011 at 3:04 PM, John Delacour <johndelacour [at] gmail.com>wrote:

> On 15 January 2011 07:52, Emeka <emekamicro [at] gmail.com> wrote:
>
> > # perl -le '$str = "the cat sat on the mat";print substr( $str, 4, -4 )'
> > Can't find string terminator "'" anywhere before EOF at -e line 1.
> >
> > rmicro [at] RMICRO-PC C:\Program Files\xampp
> > #
> >
> > It failed to work for me. Why?
>
> Because you can't use single quotes for the script-string in Windows
> cmd.exe. If you must work in the command line, then you can either
> escape all your double quotes within the string or use
> qq~double-quoted string~ , where "~" can be any ascii character that
> is not in the string itself.
>
> perl -le "$str = qq~the cat sat on the mat~; print substr( $str, 4, -4 )"
>
> If I were beginning with Perl, I certainly would not practise in the
> console but get an editor, such as SciTE
>
> <http://www.scintilla.org/SciTE.html>
>
> and run the scripts from the editor (using F5) in the case of SciTE.
>
> JD
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
> For additional commands, e-mail: beginners-help [at] perl.org
> http://learn.perl.org/
>
>
>


--
*Satajanus Nig. Ltd


*

--001636c5a30eb6f90b0499e5a711--
Emeka [ Sa, 15 Januar 2011 18:12 ] [ ID #2053239 ]

Re: doubt in substring

On 2011-01-15 08:52, Emeka wrote:

> rmicro [at] RMICRO-PC C:\Program Files\xampp
> # perl -le '$str = "the cat sat on the mat";print substr( $str, 4, -4 )'
> Can't find string terminator "'" anywhere before EOF at -e line 1.

On Windows it should probably look like:

# perl -wle "$s=q{abc def ghi jkl};print substr($s,4,-4)"

(untested)

--
Ruud

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
rvtol+usenet [ Sa, 15 Januar 2011 12:20 ] [ ID #2053255 ]

Re: doubt in substring

On Sat, Jan 15, 2011 at 03:20, Dr.Ruud <rvtol+usenet [at] isolution.nl> wrote:
> On 2011-01-15 08:52, Emeka wrote:
>
>> rmicro [at] RMICRO-PC C:\Program Files\xampp
>> # perl -le '$str =3D =A0"the cat sat on the mat";print substr( $str, 4, =
-4 )'
>> Can't find string terminator "'" anywhere before EOF at -e line 1.
>
> On Windows it should probably look like:
>
> # perl -wle "$s=3Dq{abc def ghi jkl};print substr($s,4,-4)"
>
> (untested)
>
> --
> Ruud

That worked for me on the Windoze console.

Ken Wolcott

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Kenneth Wolcott [ So, 16 Januar 2011 07:05 ] [ ID #2053256 ]
Perl » gmane.comp.lang.perl.beginners » doubt in substring

Vorheriges Thema: genbank library file
Nächstes Thema: Creating output report with topheader