Hi,
I have a question about converting some of the data in my dataset but leave some data the way it is.
I have a hash and if the key is present and the Value of the Hash equals B it should convert these number but if B is not present the data should remain the same.
my output is that all the data is converted not in the only the cases were B is present.
This is the script i have -
while ($data = <Dataset>) {
-
if (exists $hash[1]) {
-
if ($hash[2]==B) {
-
for ($i = 0; $i < length($data); $i++) {
-
$characterString = substr($data, $i, 1);
-
$newCode = $characterString;
-
if ($characterString eq "1") {
-
$newCode = "0";
-
}
-
if ($characterString eq "0") {
-
$newCode = "1";
-
}
-
if ($characterString eq "2") {
-
$newCode = "3";
-
}
-
if ($characterString eq "3") {
-
$newCode = "2";
-
}
-
substr($data, $i, 1) = $newCode;
-
}
-
print "$data\n";
-
}
-
else {
-
print $data\n";
-
}
-
I hope someone can help me with this.
13 1795 KevinADC 4,059
Recognized Expert Specialist
Do you have an array or a hash?
$hash[1] is an array index, not a hash key. Hash keys use curly brackets {} KevinADC 4,059
Recognized Expert Specialist
'B' is a string (most likely) not a number, so use 'eq' instead of '==':
Thank you for your help. I tried it like you said it is a hash so this is what i used but im not getting any output! I hope you can help me figure out what i should do! - while ($data = <Dataset>) {
-
if (exists $hash{1]} {
-
if ($hash{2} eq 'B') {
-
for ($i = 0; $i < length($data); $i++) {
-
$characterString = substr($data, $i, 1);
-
$newCode = $characterString;
-
if ($characterString eq "1") {
-
$newCode = "0";
-
}
-
if ($characterString eq "0") {
-
$newCode = "1";
-
}
-
if ($characterString eq "2") {
-
$newCode = "3";
-
}
-
if ($characterString eq "3") {
-
$newCode = "2";
-
}
-
substr($data, $i, 1) = $newCode;
-
}
-
print "$data\n";
-
}
-
else {
-
print $data\n";
-
}
-
-
Hi i want to use the keys and values of a hash to compare them with other files. But i can't acces them.
This is my code i hope somone can help! -
-
my %hash;
-
-
while( <Data> ) {
-
@elements = split /,/, $_;
-
-
if( $elements[1] ne '' ) {
-
$hash{ $elements[1] } = $elements[2];
-
}
-
}
-
-
while ($data = <Dataset>) {
-
if (exists $hash{1}) {
-
if ($hash{2} eq 'B')
-
print $data;
-
else {
-
print $data;
-
}
-
}
-
}
-
@Iris83
I'm not quite sure what you are intending to do. - $hash{ $elements[1] } = $elements[2];
Do you really mean the second and the third element? Remember, the first array element has index 0.
You are accessing $hash{1} and $hash{2}. Are 1 and 2 really the hash keys you mean? - if ($hash{2} eq 'B')
-
print $data;
-
else {print $data;
-
}
Why an if-statement when printing data in any case?
Please, can you give a short example of what your input files consist of?
Greetz, Doc
KevinADC 4,059
Recognized Expert Specialist
check you code for proper syntax:
{1]
should be:
{1}
The syntax is indeed {1} in my script but it doesn't work!
so any tips would be appreciated!
KevinADC 4,059
Recognized Expert Specialist
need to see some of the data you are working with.
I have 2 datasets one containing data like this
11,1,B
12,2,B
13,3,T
21,4,T
22,5,T
From this data i want the 2nd row to be the keys in the hash and the 3th row the values.
my 2nd data set looks like this
1 1 1 0 0
2 1 0 1 1
3 1 0 1 1
5 1 0 0 0
for example if the first key which is 1 exists and the value is B i want to reverse the data from 1 to 0 and 0 in 1. If the key is present and the value is T it should just print the normal data.
I was told that you could acces the hash keys like this $hash{1} and the values like this $hash{2} .
I hope this clarifies thing and you are able to help me with my problem. -
my %hash;
-
-
while( <Data> ) {
-
@elements = split /,/, $_;
-
-
if( $elements[1] ne '' ) {
-
$hash{ $elements[1] } = $elements[2];
-
}
-
}
-
-
while ($data = <Dataset>) {
-
if (exists $hash{1}) {
-
if ($hash{2} eq 'B') {
-
-
for ($i = 0; $i < length($data); $i++) {
-
$characterString = substr($data, $i, 1);
-
$newCode = $characterString;
-
if ($characterString eq "0") {
-
$newCode = "1";
-
}
-
if ($characterString eq "1") {
-
$newCode = "0";
-
}
-
-
substr($data, $i, 1) = $newCode;
-
print $data;
-
else {
-
print $data;
-
}
-
}
-
}
-
}
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Anders Søndergaard |
last post by:
Hi,
I'm trying to process a large filesystem (+20 million files) and keep the
directories along with summarized information about the files (sizes,
modification times, newest file and the like) in an instance hierarchy
in memory. I read the information from a Berkeley Database.
I'm keeping it in a Left-Child-Right-Sibling instance structure, that I
operate on recursively.
|
by: Itay |
last post by:
Hi all ,
Suppose i have structurs defines as follows :
struct S1
{
int n1 ;
int n2 ;
int n3 ;
};
|
by: gj |
last post by:
I have an application in Access 97 I will be rewriting in the latest
version of Access in 6 months. In the meantime, does anyone know of an
ActiveX control I can add into an Access 97 form to allow the validation
of Credit Card numbers and also processing of payments.
Ta very muchly.
GJ
|
by: mrhicks |
last post by:
Hello all,
I have a question regarding efficeny and how to find the best
approach when trying to find flag with in a structure of bit fields. I
have several structures which look similar to
typedef unsigned long int uint32; /* 32 bits */
// Up to 36 request flags, so this will take up to 3
|
by: Maury Markowitz |
last post by:
Thanks to a tremendous amount of patient help from Rob over in the interop
group I have managed to successfully wrap a vendor-provided DLL and call it
successfully from managed C# code. Now I'd like to process the data returned,
a void* buffer which I have "cast" into a byte on the C# side.
The code, like many C programs, uses casting on top of the data buffer to
impose one or more typedef'ed structs onto the void*. For instance the first...
| |
by: ecov |
last post by:
Is there any easy way to read into a dataset a file that was created
from a BCP command. The file is in a fixed length format. I would
also like to be able to write out a dataset to the same type of file
structure.
The obvious solution would be to use XML file processing however that
is not an option as I have a third party vendor that is not capable of
processing XML files.
|
by: _(d)IEGO |
last post by:
Hello everyone. I need help regarding the following:
Given the following table:
CREATE TABLE T1 (C1 nvarchar(10), C2 money)
INSERT INTO T1 VALUES ('A',1)
INSERT INTO T1 VALUES ('B',2)
INSERT INTO T1 VALUES ('C',3)
let's say that i have this table in a local server and i want to upload
|
by: surfivor |
last post by:
I may be involved in a data migration project involving databases and
creating XML feeds. Our site is PHP based, so I imagine the team might
suggest PHP, but I had a look at the PHP documentation for one of the
Pear modules for creating XML and it didn't look like much. I've used
Perl XML:Twig and I have the impression that there is more Perl stuff
available as well as the Perl stuff being well documented as I have a
Perl DBI book, a Perl...
|
by: vectorizor |
last post by:
Hi all,
I am writing an image processing algorithm that goes across an image
first row-wise and then column-wise. For illustration purposes,
imagine that for every pixels, the output is computed as the sum of
the input and its previous neighbourg. In the horizontal pass (i.e.
row-wise), the previous neighbourg is defined as the pixel on the
left. This is followed by a vertical pass, whereby the previous
neighbourg is defined as the...
|
by: dataentryoffshore |
last post by:
Get a Discount up to 60% on data entry, data capture, dataentry
services, large volume data processing and data conversion services
through offshore facilities in India. Offshore data entry also
provides form data entry, data capture, HTML/SGML coding, image
scanning, file conversion with low cost, high quality,99.98% accuracy
and time bound.
Data Conversion Services offer cost effective data conversion
projects, Outsourcing Data...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |