Solved

Assigning a string with a ' in it

Posted on 2011-03-25
14
222 Views
Last Modified: 2012-05-11
How can I assign the following data to $string?  It has a ' in the line so I'm having trouble with it.


Target Name: s02asqlp_MSSQL_DB Target Type: Microsoft SQL Server Host Name: s02asqlp.na.ipaper.com Metric Name: type Key Name: Type of Record;Record Number Key Value: Application;3653034 TimeStamp: Mar 25, 2011 10:10:28 AM CDT Severity: Warning Message: Event generated for source (SQLSERVERAGENT) at time Fri, Mar 25, 2011, 10:08:00 AM. Details - User[]:Category[Job Engine]:Description[SQL Server Scheduled Job 'Log Shipping Alert Job - Restore' (0x5147AB34F8A62A4F8CF18821274B107E) - Status: Failed - Invoked on: 2011-03-25 10:08:00 - Message: The job failed. The Job was invoked by Schedule 494 (Log Shipping Alert Job - Restore). The last step to run was step 1 (Log Shipping Alert Job - Restore). ] Rule Name: DSQLDBSL_PROD_102608472 Rule Owner: DSYSMAN Metric Value: Warning : 9F351B69978130ADE0440021283CA56A : 0 : 0 : 1 : 9F351B69978130ADE0440021283CA56A
0
Comment
Question by:David Aldridge
  • 6
  • 6
  • 2
14 Comments
 
LVL 26

Expert Comment

by:wilcoxon
ID: 35216187
$string = <<"END_STRING";
Target Name: s02asqlp_MSSQL_DB Target Type: Microsoft SQL Server Host Name: s02asqlp.na.ipaper.com Metric Name: type Key Name: Type of Record;Record Number Key Value: Application;3653034 TimeStamp: Mar 25, 2011 10:10:28 AM CDT Severity: Warning Message: Event generated for source (SQLSERVERAGENT) at time Fri, Mar 25, 2011, 10:08:00 AM. Details - User[]:Category[Job Engine]:Description[SQL Server Scheduled Job 'Log Shipping Alert Job - Restore' (0x5147AB34F8A62A4F8CF18821274B107E) - Status: Failed - Invoked on: 2011-03-25 10:08:00 - Message: The job failed. The Job was invoked by Schedule 494 (Log Shipping Alert Job - Restore). The last step to run was step 1 (Log Shipping Alert Job - Restore). ] Rule Name: DSQLDBSL_PROD_102608472 Rule Owner: DSYSMAN Metric Value: Warning : 9F351B69978130ADE0440021283CA56A : 0 : 0 : 1 : 9F351B69978130ADE0440021283CA56A
END_STRING
0
 
LVL 26

Accepted Solution

by:
wilcoxon earned 400 total points
ID: 35216200
Or if you want to make sure nothing in the data gets interpolated, you can use

$string = <<'END_STRING';

as the opening line.
0
 
LVL 4

Assisted Solution

by:dagesi
dagesi earned 100 total points
ID: 35216259
Considering the size, wilcoxon's option is probably best.

For smaller amounts, use q, where everything contained within the parens becomes part of the string.

$bar = q(everything here is included, including the 'quotes');
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:David Aldridge
ID: 35216468
Ok, the $string<<'END_STRING'; option seems to be working, but what if I want to get the data from @ARGV?  Sorry.. I should have added that to the original question.  That data is passed to the script.
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 35216611
I don't follow.  Is the data in $ARGV[0] or is it one line per @ARGV element or something else?

If the data is already in @ARGV, you can just assign it to string:

$string = shift; # or $string = $ARGV[0];
#or
$string = join "\n", @ARGV;

If you are saying the issue is a shell issue then the easiest thing to do is to put the data in a file and call your script as:

script.pl < file_containing_data

and the script could have:

$string = join '', <>;
0
 
LVL 1

Author Comment

by:David Aldridge
ID: 35216873
Currently, I'm getting the data in like this:

my $string = join(' ', @ARGV) or die;

It gets assigned, but it has the extra ' in it so when I try to use it to remove unwanted data like:

if ( $string =~ /Warning \: .* \: 0 \: 0 \: 1 \: .*/ ) {      
      $string =~ s/Warning \: .* \: 0 \: 0 \: 1 \: .*//;
}

It breaks because of the extra '.
0
 
LVL 1

Author Comment

by:David Aldridge
ID: 35216900
Sorry, I guess I could have been a bit more clear in the beginning.
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 35217178
What makes you think it is breaking because of the extra ' in the data?

What are you trying to do with your code?  It is doing exactly what you are telling it (which may not be what you actually want).
0
 
LVL 1

Author Comment

by:David Aldridge
ID: 35217868
The "Warning" section which is at the end, isn't included in the substitution because of the extra ' in the string.
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 35217918
How so?  The final warning message is removed?

See blocks below...
### text after running your code
Target Name: s02asqlp_MSSQL_DB Target Type: Microsoft SQL Server Host Name: s02asqlp.na.ipaper.com Metric Name: type Key Name: Type of Record;Record Number Key Value: Application;3653034 TimeStamp: Mar 25, 2011 10:10:28 AM CDT Severity: Warning Message: Event generated for source (SQLSERVERAGENT) at time Fri, Mar 25, 2011, 10:08:00 AM. Details - User[]:Category[Job Engine]:Description[SQL Server Scheduled Job 'Log Shipping Alert Job - Restore' (0x5147AB34F8A62A4F8CF18821274B107E) - Status: Failed - Invoked on: 2011-03-25 10:08:00 - Message: The job failed. The Job was invoked by Schedule 494 (Log Shipping Alert Job - Restore). The last step to run was step 1 (Log Shipping Alert Job - Restore). ] Rule Name: DSQLDBSL_PROD_102608472 Rule Owner: DSYSMAN Metric Value:

Open in new window

### original text
Target Name: s02asqlp_MSSQL_DB Target Type: Microsoft SQL Server Host Name: s02asqlp.na.ipaper.com Metric Name: type Key Name: Type of Record;Record Number Key Value: Application;3653034 TimeStamp: Mar 25, 2011 10:10:28 AM CDT Severity: Warning Message: Event generated for source (SQLSERVERAGENT) at time Fri, Mar 25, 2011, 10:08:00 AM. Details - User[]:Category[Job Engine]:Description[SQL Server Scheduled Job 'Log Shipping Alert Job - Restore' (0x5147AB34F8A62A4F8CF18821274B107E) - Status: Failed - Invoked on: 2011-03-25 10:08:00 - Message: The job failed. The Job was invoked by Schedule 494 (Log Shipping Alert Job - Restore). The last step to run was step 1 (Log Shipping Alert Job - Restore). ] Rule Name: DSQLDBSL_PROD_102608472 Rule Owner: DSYSMAN Metric Value: Warning : 9F351B69978130ADE0440021283CA56A : 0 : 0 : 1 : 9F351B69978130ADE0440021283CA56A

Open in new window

0
 
LVL 1

Author Comment

by:David Aldridge
ID: 35217977
I get "Bareword found where operator expected, near "Log"
Syntax error, near "Log Shipping "
Bad name after Restore'.
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 35218013
That error is not coming from the code you posted (at least I'm not getting it).  Can you post your whole script?  And exactly how is the script being called?
0
 
LVL 1

Author Comment

by:David Aldridge
ID: 35218432
I should have known someone changed something.  The application sending the trap was modified.  Thank you for your help and the code you originally gave me will come to great use!

Sorry for taking so much of your time when I should have done a little more snooping around.
0
 
LVL 4

Expert Comment

by:dagesi
ID: 35218579
thx for the assist...
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Question about @INC variable in perl 1 65
Parse csv file and generate graphs in HTML in bash 8 235
Export Variables in Perl 3 85
Perl Snippet to Parse String 1 22
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question