473,382 Members | 1,313 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How is this string being used as an array of sums?

if $mystring equals this:
"1=2,2,4,3,3,3,1,2,4,2,4,2,2,2,4|2=4,3,3,2,4,2,3,3 ,2,2,3,3,4,5,2|3=1,4,2,4,4,5,4,2,3,4,5,5,2,3,5"

and I access it like this:
$mystring{1}

The value is 40, which is the sum of the first section of the string (2,2,4,3,3,3,1,2,4,2,4,2,2,2,4)

What kind of construct is this where the brackets are used on the string as if it were some kind of array and the result is the sum of part of the string? What do I look for to look this up?
Feb 9 '11 #1
2 1490
miller
1,089 Expert 1GB
The fact that returns anything should be treated as a fluke and not used in any relied upon way.

Always use strict; at the beginning of your perl programs and declare your variables with my.
Feb 10 '11 #2
rovf
41
Expand|Select|Wrap|Line Numbers
  1. $ perl -lwe 'use strict; my $mystring="1=2,2,4,3,3,3,1,2,4,2,4,2,2,2,4|2=4,3,3,
  2. 2,4,2,3,3 ,2,2,3,3,4,5,2|3=1,4,2,4,4,5,4,2,3,4,5,5,2,3,5"; my %mystring=(!!$mystring => length($m
  3. ystring)); print $mystring{1}'
  4.  
96

To get an even more accurate answer, please post a small, but complete program, showing your problem.
Feb 10 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: D. Alvarado | last post by:
Hi, I have this arr $months = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); and I would like to take this...
2
by: marco | last post by:
hi, i'm trying to get a board with relays working under c++, i have a sample code in visual basic to compose a string that is send to the serial port but i am confused how to translate it to a...
1
by: wonil kim | last post by:
Hello all, I am new guy on C#. So, my question will be very simple to you guys here. I want to use string constants array from C# like C++ like below. in C++ : char const * const...
13
by: Dan V. | last post by:
How do I create a one line text file with these control codes? e.g.: 144 = 0x90 and 147 = 0x93? I am trying to create a one line text file with these characters all one one row with no spaces. ...
2
by: bluebeta | last post by:
Hi, I am using embedded visual C++ 4.0 and I want to use function strtok to split string into array. my sample code is as below: ...
4
by: mistral | last post by:
Can anyone help to identify what this encryption used in this script? <html> <body> <script type="text/javascript" language="JavaScript"> function decrypt_p(x){ var l=x.length, b=1024,...
1
by: sunil68 | last post by:
I am able to pass the string to array of string please help me out with this problem string s ="This is a hat"; and the output should be like this This is a hat
5
by: sherifffruitfly | last post by:
Hi all, I just wrote this up real quick, and it seems to work with a bunch of input strings (with and without spaces) except for the one in the code below: string input = "this is a string";...
1
by: (2b|!2b)==? | last post by:
I am expecting a string of this format: "id1:param1,param2;id2:param1,param2,param3;id" The tokens are seperated by semicolon ";" However each token is really a struct of the following...
5
by: da1978 | last post by:
Hi experts, I need to convert a string or a Byte array to a string byte array. Its relatively easy to convert a string to an char array or a byte array but not a STRING byte array. i.e. ...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.