string length?

J

John Smith

I'm sorta new so I don't imagine you mean:

$a="12345"
print("length of a = length($a) \n";
 
B

Barry Kimelman

[This followup was posted to comp.lang.perl.misc]

how do I get the string length of a string?
/B

$length = length $string;

Note : you can use the perldoc command to get a lot of info on perl
features.
 
C

Chris Mattern

Abigail said:
Bob Smith ([email protected]) wrote on MMMDCLXXIV September MCMXCIII in
<URL:'' how do I get the string length of a string?


That's why Perl has the handy chop function!

$str = "I want to know the length";
$length = 0;
while ($str ne "") {
$tmp = $length + 1;
chop $str;
$length = $tmp;
}
Now, is that a nice thing to do to a newbie, Abigail?

Chris Mattern
 
U

Uri Guttman

JS> I'm sorta new so I don't imagine you mean:
JS> $a="12345"
JS> print("length of a = length($a) \n";

if you are new here, you should test your code before posting here. that
one has a nice bug.

uri
 
J

Jürgen Exner

Bob said:
how do I get the string length of a string?

Finally!!
It has been months and months since we had this self-answering question the
last time.

jue
 
T

Trent Curry

Purl said:
Barry said:
[This followup was posted to comp.lang.perl.misc]

I am curious why you add this to your articles.

Reading your article in this newsgroup, is indicative
of your article being posted in this newsgroup, yes?


Purl Gurl

How is that off topic?

--
Trent Curry

perl -e
'($s=qq/e29716770256864702379602c6275605/)=~s!([0-9a-f]{2})!pack("h2",$1)!eg
;print(reverse("$s")."\n");'
 
T

Trent Curry

Chris said:
Now, is that a nice thing to do to a newbie, Abigail?

Chris Mattern

I don't think there was any reason to do that at all. It's just confusing a
new person even more and could just result in him coming back whining about
why the code isn't working. If you don't like newbie questions why respond
to them?

--
Trent Curry

perl -e
'($s=qq/e29716770256864702379602c6275605/)=~s!([0-9a-f]{2})!pack("h2",$1)!eg
;print(reverse("$s")."\n");'
 
C

Chris Mattern

Trent said:
I don't think there was any reason to do that at all. It's just confusing a
new person even more and could just result in him coming back whining about
why the code isn't working.

Not work? What in the above code does not work? It's horribly ugly and
incredibly ludicrous, but it does *work* (it does destroy the source string,
but then the original poster never said he needed it preserved...).
If you don't like newbie questions why respond
to them?
Even newbies should have read the FAQ, and thus know how to read the
basic documentation. That may have been a bit harsh, though.

Chris Mattern
 
T

Tore Aursand

perldoc -f length

Actually, that gives you the _documentation_ for the 'length' function. :)
The correct answer is of course:

my $string = 'this is a string';
my $length = length( $string );

<g>


--
Tore Aursand <[email protected]>

"You know the world is going crazy when the best rapper is white, the best
golfer is black, France is accusing US of arrogance and Germany doesn't
want to go to war."
 
T

Trent Curry

Purl said:
(snipped)


My article is posted to comp.lang.perl.misc which is
this newsgroup, for those not sure where they are.


[This followup was posted to comp.lang.perl.misc]
I am curious why you add this to your articles.
Reading your article in this newsgroup, is indicative
of your article being posted in this newsgroup, yes?

How is that off topic?

I find no references to "off topic" within this thread.
Perhaps an article has not shown up on my news server
which makes mention of "off topic."

It was in your subject line for the post I replied to...

--
Trent Curry

perl -e
'($s=qq/e29716770256864702379602c6275605/)=~s!([0-9a-f]{2})!pack("h2",$1)!eg
;print(reverse("$s")."\n");'
 
T

Trent Curry

Chris said:
Not work? What in the above code does not work? It's horribly ugly
and incredibly ludicrous, but it does *work* (it does destroy the
source string, but then the original poster never said he needed it
preserved...).

True, it working in the sense of being able to compile and run, but it
doesn't work in any way the the op would expect, espially being a beginning,
ehich if you ask me, is just a mean thing to do and serves no one.
Even newbies should have read the FAQ, and thus know how to read the
basic documentation. That may have been a bit harsh, though.

Of course. But what most of the experts don't take into account that newbies
may not even know such FAQs exist. Pointing out sources for them is one
thing, giving code that only serves to confuse them is another.



--
Trent Curry

perl -e
'($s=qq/e29716770256864702379602c6275605/)=~s!([0-9a-f]{2})!pack("h2",$1)!eg
;print(reverse("$s")."\n");'
 
T

Trent Curry

Abigail said:
Chris Mattern ([email protected]) wrote on MMMDCLXXIV September MCMXCIII



Well, I'd considered roasting him over a fire, and feeding him to
my dog, but my dog doesn't like Bobs. (The dog is a sysadmin).

I'm sorry, but where do you get off "flaming" someone like this?
(Sorry I coudln't resist ;p)

Now really, why beat this poor newbie too death?

--
Trent Curry

perl -e
'($s=qq/e29716770256864702379602c6275605/)=~s!([0-9a-f]{2})!pack("h2",$1)!eg
;print(reverse("$s")."\n");'
 
S

Sam Holden

[snip length in terms of chop]
True, it working in the sense of being able to compile and run, but it
doesn't work in any way the the op would expect, espially being a beginning,
ehich if you ask me, is just a mean thing to do and serves no one.

It places the length of the string in $length.

How is that not what the op would expect, when the op wanted to
determine the length of the string?

Seems pretty damn intuitive to me.

Placing it in the function would have been better, but Abigail was
being nice and realised the OP probably wouldn't know what a function
was and would be confused by the syntax.
Of course. But what most of the experts don't take into account that newbies
may not even know such FAQs exist. Pointing out sources for them is one
thing, giving code that only serves to confuse them is another.

They are pointed out in the standard places, not for comp.lang.perl.misc
but for usenet in general. As well as in docs that come with perl.

Though of course people who would use a language without glancing at the
docs might be expected to post to usenet without reading the "rules".
Those people would probably also push to the front of the line at the
rollercoaster, since they wouldn't bother reading the "line up here"
sign, or learning about society's default rules.

Luckily in most places you need a license to drive a car, so these
people don't go running red lights because they didn't bother reading
the road rules.

A license to post would be a terrible thing, so instead we have
social pressure.

If you push to the front of the line at the rollercoaster you can expect
to not be treated so well by those around you. Just like if you post
FAQs answered by searching almost *anywhere* for the subject you used,
you can expect to not be treated in a nice manner.

You'll get cryptic answers, RTFMs, flames, plonks, and be silently
ignored forever by many knowledgable posters. Reap what you sow and
all that...
 
A

Anno Siegel

Trent Curry said:
True, it working in the sense of being able to compile and run, but it
doesn't work in any way the the op would expect, espially being a beginning,
ehich if you ask me, is just a mean thing to do and serves no one.


Of course. But what most of the experts don't take into account that newbies
may not even know such FAQs exist. Pointing out sources for them is one
thing, giving code that only serves to confuse them is another.

Oh, come on... Abigail didn't post this in a vacuum. There are
plenty straight answers in the thread. Even a beginner can see
the code isn't serious.

Anno
 
T

Trent Curry

Abigail said:
But more than lazy people, I hate whiners who whine if you don't
want to kiss up to people.

Then you miss understand me and proceed to a false conclusion of my intent.
I was not trying to be anyone's lawyer. Actually I was poking fun at
Abigail's "rosting over a fire" gag in my last reply. I was not in any way
trying to motivate "kissing up" to anyone.

I'm sorry, but what real gain is there from publically announcing additions
to one's kill file?

--
Trent Curry

perl -e
'($s=qq/e29716770256864702379602c6275605/)=~s!([0-9a-f]{2})!pack("h2",$1)!eg
;print(reverse("$s")."\n");'
 
S

Sam Holden

Then you miss understand me and proceed to a false conclusion of my intent.
I was not trying to be anyone's lawyer. Actually I was poking fun at
Abigail's "rosting over a fire" gag in my last reply. I was not in any way
trying to motivate "kissing up" to anyone.

I suspect Abigail was referring to all your posts in the thread and not
just the specific post that was replied to.
I'm sorry, but what real gain is there from publically announcing additions
to one's kill file?

Other people see examples of wht not to do if they dont want to also end
up in that person's killfile. And I guess what to do if they do want to
end up in that person's killfile. And possibly a guide to others who
didn't follow the thread as to a poster who's posts might be worth
checking to see if the killfile entry should be duplicated. The second
two reasons are less likely and less important, obviously, but that's
three just off the top of my head.

I consider it of great benefit to know what I should avoid in order to
have a chance of knowledgable, experienced perl programmers answering a
question I may have in the future.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,104
Latest member
LesliVqm09
Top